Example #1
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();
        }
        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();
        }
Example #3
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();
        }
Example #4
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();
        }
        ///////////////////////////////////////////////////////////////////////
        // ParsePage
        ///////////////////////////////////////////////////////////////////////
        private static void ParsePage(Pdfix pdfix, PdfPage page, String outDir)
        {
            // get pageMap for the current page
            PdePageMap pageMap = page.AcquirePageMap();

            if (pageMap == null)
            {
                throw new Exception(pdfix.GetError());
            }
            if (!pageMap.CreateElements(null, null))
            {
                throw new Exception(pdfix.GetError());
            }

            // get page container
            PdeElement container = pageMap.GetElement();

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

            // parse children recursivelly
            ParseElement(container, outDir);

            pageMap.Release();
        }
        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();
        }
Example #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();
        }
Example #8
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();
        }
Example #11
0
        public static void Run(
            String openPath,                    // source PDF document
            String savePath,                    // output PDF document
            String configPath                   // configuration file
            )
        {
            Pdfix pdfix = PdfixEngine.Instance;

            // open the document
            var doc = pdfix.OpenDoc(openPath, "");

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

            using (var stm = pdfix.CreateFileStream(configPath, PsFileMode.kPsReadOnly))
            {
                var doc_prelight = doc.GetTemplate();
                if (doc_prelight == null)
                {
                    throw new Exception(pdfix.GetError());
                }
                doc_prelight.LoadFromStream(stm, PsDataFormat.kDataFormatJson);
            }

            // define a cancel progress callback
            PdfCancelDelegate cancel_callback = (data) =>
            {
                // to cancel the process return 1
                Console.WriteLine("PdfCancelProc callback was called");
                return(0);
            };

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

            if (!doc.AddTags(cancel_callback, 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 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();
        }
Example #13
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();
        }
Example #14
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 email,                                           // authorization email
            String licenseKey                                       // license key
            )
        {
            Pdfix pdfix = new Pdfix();

            if (pdfix == null)
            {
                throw new Exception("Pdfix initialization fail. Please set correct email and license key.");
            }

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

            if (!pdfix.IsAuthorized())
            {
                throw new Exception("Pdfix Authorization fail");
            }

            // ...

            pdfix.Destroy();
        }
Example #16
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();
        }
        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;
        }
        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();
        }
Example #19
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();
        }
        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;
        }
Example #21
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 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();
        }
Example #23
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();
        }
Example #25
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
            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();
        }
Example #27
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();
        }
        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());
            }


            // 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, Pdfix.kSaveFull))
            {
                throw new Exception(pdfix.GetError());
            }

            doc.Close();
        }
        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());
            }

            for (int i = 0; i < doc.GetNumPages(); i++)
            {
                var page = doc.AcquirePage(i);
                for (int j = page.GetNumAnnots() - 1; j >= 0; j--)
                {
                    var annot = page.GetAnnot(j);
                    if (annot == null || annot.GetSubtype() == PdfAnnotSubtype.kAnnotLink)
                    {
                        continue;
                    }
                    if (!page.FlattenAnnot(annot))
                    {
                        throw new Exception(pdfix.GetError());
                    }
                }
                page.SetContent();
                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,                            // output PDF document
            PdfFlattenAnnotsParams flattenAnnotsParams  // flatten annots 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());
            }

            if (!doc.FlattenAnnots(flattenAnnotsParams))
            {
                throw new Exception(pdfix.GetError());
            }

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

            doc.Close();
            pdfix.Destroy();
        }