public static void Run(
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            doc = pdfix.OpenDoc(openPath, "");
            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            String[] op = new string[4];
            op[0] = "count pages";
            op[1] = "remove annotations";
            op[2] = "place watermark";
            op[3] = "extract table";

            for (int j = 0; j < 4; j++)
            {
                t[j]      = new Thread(DoSomething);
                t[j].Name = op[j];
                t[j].Start();
            }

            for (int j = 0; j < 4; j++)
            {
                t[j].Join();
            }

            doc.Close();
            doc = null;
            pdfix.Destroy();
            pdfix = null;
        }
Пример #2
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            PdsObject rootObj = doc.GetRootObject();

            ParseObject(rootObj, 1);

            doc.Close();
            pdfix.Destroy();
        }
Пример #3
0
        public static void Run(
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            bool preflight,                             // preflight page before tagging
            String language,                            // document reading language
            String title,                               // document title
            String configPath                           // configuration file
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            var doc_template = doc.GetTemplate();

            // convert to PDF/UA
            PdfAccessibleParams accParams = new PdfAccessibleParams();

            if (!doc.MakeAccessible(accParams, null, null))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
Пример #4
0
        public static void Run(
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            var rootObj = doc.GetRootObject();
            var layers  = ReadOCGLayers.ReadLayerNames(rootObj);

            var page = doc.AcquirePage(0);

            foreach (KeyValuePair <string, int> layer in layers)
            {
                Console.WriteLine("Text in layer " + layer.Key + "(" + layer.Value.ToString() + ")");
                var content = page.GetContent();
                for (var i = 0; i < content.GetNumObjects(); i++)
                {
                    var page_obj = content.GetObject(i);
                    CheckPageObject(page_obj, layer);
                }
            }
            page.Release();
            doc.Close();
        }
Пример #5
0
        public static void Run(
            String openPath,                            // source PDF document
            String savePath                             // output PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.RemoveTags(null, null))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.AddTags(null, null))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
        public static void Run(
            String openPath,                           // source PDF document
            String savePath,                           // output TXT document
            String configPath                          // configuration file
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // iterate through pages and parse each page individually
            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                PdfPage page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                ParsePage(pdfix, page, savePath);

                page.Release();
            }

            Console.WriteLine(tableIndex + " tables detected");

            doc.Close();
        }
Пример #7
0
        public static void Run(
            String openPath,                    // source PDF document
            String savePath
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                var page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                var content = page.GetContent();
                for (int j = 0; j < content.GetNumObjects(); j++)
                {
                    ProcessPageObject(page, content.GetObject(j), savePath);
                }
                page.Release();
            }

            doc.Close();
        }
Пример #8
0
        public static void Run(
            String openPath                     // source PDF document
            )
        {
            var pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            Console.WriteLine("detect form field tab order");
            ProcessFormFieldsViaPages(doc);

            Console.WriteLine("");
            Console.WriteLine("********************************************************");
            Console.WriteLine("");

            Console.WriteLine("map all document fields, some spccific proerties may ne inaccesscible");
            ProcessDocumentFormFields(doc);

            doc.Close();
        }
Пример #9
0
        public static void Run(
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // iterate through pages and parse each page individually
            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                PdfPage page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                ParsePage(pdfix, page);
                page.Release();
            }

            doc.Close();
        }
Пример #10
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath                             // dest PDF document
            )
        {
            pdfix = new Pdfix();
            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // cleanup any previous structure tree
            if (!doc.RemoveTags(null, IntPtr.Zero))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // autotag document first
            if (!doc.AddTags(null, IntPtr.Zero))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // read document structure tree
            PdsStructTree struct_tree = doc.GetStructTree();

            if (struct_tree == null)
            {
                Console.WriteLine("No Tags available");
            }
            else
            {
                for (var i = 0; i < struct_tree.GetNumKids(); i++)
                {
                    PdsObject        kid_object  = struct_tree.GetKidObject(i);
                    PdsStructElement struct_elem = struct_tree.AcquireStructElement(kid_object);
                    ProcessStructElement(doc, struct_elem, "");
                    struct_elem.Release();
                }
            }


            doc.Close();
            pdfix.Destroy();
        }
Пример #11
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            String dataPath,                            // path to OCR data
            String language                             // default OCR language
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            OcrTesseract ocr = new OcrTesseract();

            if (ocr == null)
            {
                throw new Exception("OcrTesseract initialization fail");
            }

            if (!ocr.Initialize(pdfix))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            ocr.SetLanguage(language);
            ocr.SetDataPath(dataPath);

            TesseractDoc ocrDoc = ocr.OpenOcrDoc(doc);

            if (ocrDoc == null)
            {
                throw new Exception(pdfix.GetError());
            }


            //if (!ocrDoc.Save(savePath, ocrParams, null, IntPtr.Zero))
            //    throw new Exception(pdfix.GetError());

            ocrDoc.Close();
            doc.Close();
            pdfix.Destroy();
        }
        public static void Run(
            String openPath,                            // source PDF document
            String savePath                             // dest PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // cleanup any previous structure tree
            if (!doc.RemoveTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // autotag document first
            if (!doc.AddTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // get the struct tree
            PdsStructTree struct_tree = doc.GetStructTree();

            if (struct_tree == null)
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // tag text on the bottom of the page as artifact
            for (int i = 0; i < struct_tree.GetNumChildren(); i++)
            {
                PdsObject        kid_obj  = struct_tree.GetChildObject(i);
                PdsStructElement kid_elem = struct_tree.GetStructElementFromObject(kid_obj);
                RemoveParagraph(kid_elem);
            }

            // the struct tree was updates, save page content on each page to apply changes
            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                PdfPage page = doc.AcquirePage(i);
                MarkUntaggedObjectsAsArtifact(page);
                page.Release();
            }

            if (!doc.Save(savePath, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath                             // dest PDF document
            )
        {
            pdfix = new Pdfix();
            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }


            // get the struct tree
            PdsStructTree struct_tree = doc.GetStructTree();

            if (struct_tree == null)
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            PdsStructElement figure = GetFirstFigure(struct_tree);

            if (figure == null)
            {
                throw new Exception("No figure found.");
            }

            if (!figure.SetAlt("This is a new alternate text"))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, PdfSaveFlags.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
            pdfix.Destroy();
        }
Пример #14
0
 private void flushFileInBrowser02()
 {
     if (!FlushInBrowser)
     {
         // close the document without closing the underlying stream
         PdfWriter.CloseStream = false;
         PdfDoc.Close();
         //_pdfRptData.PdfStreamOutput.Position = 0;
         return;
     }
 }
Пример #15
0
        public static void Run(
            String openPath,                            // source PDF document
            String savePath                             // output PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            PdfPage page = doc.AcquirePage(0);

            if (page == null)
            {
                throw new Exception(pdfix.GetError());
            }

            PdfRect cropBox = page.GetCropBox();

            // place annotation to the middle of the page
            PdfRect annotRect = new PdfRect();

            annotRect.left   = (float)((cropBox.right + cropBox.left) / 2.0) - 10;
            annotRect.bottom = (float)((cropBox.top + cropBox.bottom) / 2.0) - 10;
            annotRect.right  = (float)((cropBox.right + cropBox.left) / 2.0) + 10;
            annotRect.top    = (float)((cropBox.top + cropBox.bottom) / 2.0) + 10;

            PdfTextAnnot annot = (PdfTextAnnot)page.CreateAnnot(PdfAnnotSubtype.kAnnotText, annotRect);

            page.AddAnnot(-1, annot);
            if (annot == null)
            {
                throw new Exception(pdfix.GetError());
            }
            annot.SetAuthor(@"Peter Brown");
            annot.SetContents(@"This is my comment.");
            annot.AddReply(@"Mark Fish", @"This is some reply.");

            page.Release();

            if (!doc.Save(savePath, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
Пример #16
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            String pfxPath,                             // pfx file PKCS 12 certificate
            String pfxPassword                          // pfx password
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDigSig digSig = pdfix.CreateDigSig();

            if (digSig == null)
            {
                throw new Exception(pdfix.GetError());
            }

            digSig.SetReason("Testing PDFix API");
            digSig.SetLocation("Location");
            digSig.SetContactInfo("*****@*****.**");
            if (!digSig.SetPfxFile(pfxPath, pfxPassword))
            {
                throw new Exception(pdfix.GetError());
            }
            if (!digSig.SignDoc(doc, savePath))
            {
                throw new Exception(pdfix.GetError());
            }
            digSig.Destroy();

            doc.Close();
            pdfix.Destroy();
        }
Пример #17
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            String imgPath,                             // watermark to apply
            PdfWatermarkParams watermarkParams          // watermark params
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // set watermark params
            watermarkParams.page_range.start_page      = 1;
            watermarkParams.page_range.end_page        = 3;
            watermarkParams.page_range.page_range_spec = PdfPageRangeType.kEvenPagesOnly;
            watermarkParams.h_value = 10;
            watermarkParams.v_value = 10;
            watermarkParams.scale   = 0.5;
            watermarkParams.opacity = 0.5;

            if (!doc.AddWatermarkFromImage(watermarkParams, imgPath))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, PdfSaveFlags.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
            pdfix.Destroy();
        }
        public static void Run(
            String openPath,                            // source PDF document
            String savePath                             // dest PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // cleanup any previous structure tree
            if (!doc.RemoveTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // autotag document first
            if (!doc.AddTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // get the struct tree
            PdsStructTree struct_tree = doc.GetStructTree();

            if (struct_tree == null)
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // move paragraph to the back of it's parent
            if (!MoveParagraphToParent(struct_tree))
            {
                throw new Exception("No table found.");
            }

            if (!doc.Save(savePath, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
Пример #19
0
        public static void Run(
            String email,                              // authorization email
            String licenseKey,                         // authorization license key
            String openPath,                           // source PDF document
            String savePath,                           // output TXT document
            String configPath                          // configuration file
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            StreamWriter file = new System.IO.StreamWriter(savePath);

            // iterate through pages and parse each page individually
            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                PdfPage page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                ParsePage(pdfix, page, file);
                page.Release();
            }

            file.Close();

            doc.Close();
            pdfix.Destroy();
        }
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath                             // source PDF document
            )
        {
            pdfix = new Pdfix();
            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            doc = pdfix.OpenDoc(openPath, "");
            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            String[] op = new string[4];
            op[0] = "count pages";
            op[1] = "remove annotations";
            op[2] = "place watermark";
            op[3] = "extract table";

            for (int j = 0; j < 4; j++)
            {
                t[j]      = new Thread(DoSomething);
                t[j].Name = op[j];
                t[j].Start();
            }

            for (int j = 0; j < 4; j++)
            {
                t[j].Join();
            }

            doc.Close();
            doc = null;
            pdfix.Destroy();
            pdfix = null;
        }
Пример #21
0
        private void flushFileInBrowser()
        {
            if (!FlushInBrowser)
            {
                return;
            }

            // close the document without closing the underlying stream
            PdfWriter.CloseStream = false;
            PdfDoc.Close();
            _pdfRptData.PdfStreamOutput.Position = 0;

            // write pdf bytes to output stream
            var pdf = ((MemoryStream)_pdfRptData.PdfStreamOutput).ToArray();

            SoftHttpContext.FlushInBrowser(_pdfRptData.FileName, pdf, FlushType);
        }
Пример #22
0
        private byte[] flushFileInBrowser()
        {
            if (!OutputAsByteArray)
            {
                return(null);
            }

            // close the document without closing the underlying stream
            PdfWriter.CloseStream = false;
            PdfDoc.Close();
            _pdfRptData.PdfStreamOutput.Position = 0;

            // write pdf bytes to output stream
            var pdf = ((MemoryStream)_pdfRptData.PdfStreamOutput).ToArray();

            return(pdf);
        }
Пример #23
0
        public static void Run(
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // cleanup any previous structure tree
            if (!doc.RemoveTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // autotag document first
            if (!doc.AddTags(null, null))
            {
                throw new Exception(pdfix.GetErrorType().ToString());
            }

            // read document structure tree
            PdsStructTree struct_tree = doc.GetStructTree();

            if (struct_tree == null)
            {
                Console.WriteLine("No Tags available");
            }
            else
            {
                for (var i = 0; i < struct_tree.GetNumChildren(); i++)
                {
                    PdsObject        kid_object  = struct_tree.GetChildObject(i);
                    PdsStructElement struct_elem = struct_tree.GetStructElementFromObject(kid_object);
                    ProcessStructElement(doc, struct_elem, "");
                }
            }


            doc.Close();
        }
        public static void Run(
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            String dataPath,                            // path to OCR data
            String language                             // default OCR language
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            OcrTesseract ocr = new OcrTesseract();

            if (ocr == null)
            {
                throw new Exception("OcrTesseract initialization fail");
            }

            if (!ocr.Initialize(pdfix))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            ocr.SetLanguage(language);
            ocr.SetDataPath(dataPath);

            TesseractDoc ocrDoc = ocr.OpenOcrDoc(doc);

            if (ocrDoc == null)
            {
                throw new Exception(pdfix.GetError());
            }


            //if (!ocrDoc.Save(savePath, ocrParams, null, null))
            //    throw new Exception(pdfix.GetError());

            ocrDoc.Close();
            doc.Close();
        }
Пример #25
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath,                            // output PDF document
            String language,                            // document reading language
            String title,                               // document title
            String configPath                           // configuration file
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            // convert to PDF/UA
            PdfAccessibleParams accParams = new PdfAccessibleParams();

            if (!doc.MakeAccessible(accParams, null, IntPtr.Zero))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, PdfSaveFlags.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
            pdfix.Destroy();
        }
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath,                            // source PDF document
            String savePath                             // output PDF document
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.RemoveTags(null, IntPtr.Zero))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.AddTags(null, IntPtr.Zero))
            {
                throw new Exception(pdfix.GetError());
            }

            if (!doc.Save(savePath, PdfSaveFlags.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
            pdfix.Destroy();
        }
Пример #27
0
        public static void Run(
            String email,                       // authorization email
            String licenseKey,                  // authorization license key
            String openPath,                    // source PDF document
            String savePath
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }
            _pdfix = pdfix;

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception("Authorization fail. " + pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                var page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                for (int j = 0; j < page.GetNumPageObjects(); j++)
                {
                    ProcessPageObject(page, page.GetPageObject(i), savePath);
                }
                page.Release();
            }

            doc.Close();
            pdfix.Destroy();
        }
        public static void Run(
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            PdsObject rootObj = doc.GetRootObject();

            ParseObject(rootObj, 1);

            doc.Close();
        }
Пример #29
0
        public static void Run(
            String email,                               // authorization email
            String licenseKey,                          // authorization license key
            String openPath                             // source PDF document
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail");
            }

            if (!pdfix.Authorize(email, licenseKey))
            {
                throw new Exception(pdfix.GetError());
            }

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            var rootObj = doc.GetRootObject();
            var layers  = ReadOCGLayers.ReadLayerNames(rootObj);

            var page = doc.AcquirePage(0);

            foreach (KeyValuePair <string, int> layer in layers)
            {
                Console.WriteLine("Text in layer " + layer.Key + "(" + layer.Value.ToString() + ")");
                for (var i = 0; i < page.GetNumPageObjects(); i++)
                {
                    var page_obj = page.GetPageObject(i);
                    CheckPageObject(page_obj, layer);
                }
            }
            page.Release();
            doc.Close();
            pdfix.Destroy();
        }
Пример #30
0
        public static void Run(
            String openPath,                            // source PDF document
            String savePath,                            // output XML document
            String configPath                           // configuration file
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            PdfDoc doc = pdfix.OpenDoc(openPath, "");

            if (doc == null)
            {
                throw new Exception(pdfix.GetError());
            }

            StreamWriter file = new System.IO.StreamWriter(savePath);

            //pdfix.CreateCustomStream()

            // XML headers
            file.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
            file.Write("<!--Created from PDF via PDFix-->\n");
            file.Write("<Document>\n");

            PsMetadata metadata = doc.GetMetadata();


            // iterate through pages and parse each page individually
            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                PdfPage page = doc.AcquirePage(i);
                if (page == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                ParsePage(pdfix, page, file);
                page.Release();
            }

            file.Close();

            doc.Close();
        }