static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path = "../../TestFiles/";

            try
            {
                Console.WriteLine("-------------------------------------------------");
                Console.WriteLine("Sample 1 - Extract text data from all pages in the document.");

                // Open the test file
                Console.WriteLine("Opening the input pdf...");
                using (PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf"))
                    using (ElementReader page_reader = new ElementReader())
                    {
                        doc.InitSecurityHandler();

                        PageIterator itr;
                        for (itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())                            //  Read every page
                        {
                            page_reader.Begin(itr.Current());
                            ProcessElements(page_reader);
                            page_reader.End();
                        }
                        Console.WriteLine("Done.");
                    }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Initialize PDFNet before using any PDFTron related
            // classes and methods (some exceptions can be found in API)
            PDFNet.Initialize();

            // Using PDFNet related classes and methods, must catch or throw PDFNetException
            try
            {
                using (PDFDoc doc = new PDFDoc())
                {
                    doc.InitSecurityHandler();

                    // An example of creating a new page and adding it to
                    // doc's sequence of pages
                    Page newPg = doc.PageCreate();
                    doc.PagePushBack(newPg);

                    // Save as a linearized file which is most popular
                    // and effective format for quick PDF Viewing.
                    doc.Save("linearized_output.pdf", SDFDoc.SaveOptions.e_linearized);

                    System.Console.WriteLine("Done. Results saved in linearized_output.pdf");
                }
            }
            catch (PDFNetException e)
            {
                System.Console.WriteLine(e);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();
            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";

            Console.WriteLine("_______________________________________________");
            Console.WriteLine("Opening the input pdf...");

            try             // Test  - Adjust the position of content within the page.
            {
                using (PDFDoc input_doc = new PDFDoc(input_path + "tiger.pdf"))
                {
                    input_doc.InitSecurityHandler();

                    Page pg        = input_doc.GetPage(1);
                    Rect media_box = pg.GetMediaBox();

                    media_box.x1 -= 200;                        // translate the page 200 units (1 uint = 1/72 inch)
                    media_box.x2 -= 200;

                    media_box.Update();

                    input_doc.Save(output_path + "tiger_shift.pdf", 0);
                }

                Console.WriteLine("Done. Result saved in tiger_shift...");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 4
0
        public void RunPdfTron(string input_path)
        {
            PDFNet.Initialize();

            // string output_path = "../../../../TestFiles/Output/";

            try
            {
                // Open the test file
                PDFDoc doc = new PDFDoc(input_path);
                doc.InitSecurityHandler();

                PageIterator  itr;
                ElementReader page_reader = new ElementReader();

                for (itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())        //  Read every page
                {
                    int pageno = itr.GetPageNumber();


                    page_reader.Begin(itr.Current());
                    ProcessElements(page_reader);
                    page_reader.End();
                }

                page_reader.Dispose(); // Calling Dispose() on ElementReader/Writer/Builder can result in increased performance and lower memory consumption.
                doc.Close();
            }
            catch (PDFNetException e)
            {
                ConsoleLog += e.Message;
            }

            PDFNet.Terminate();
        }
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            try
            {
                using (PDFDoc doc = new PDFDoc(input_path + "numbered.pdf"))
                {
                    doc.InitSecurityHandler();

                    // An example of using SDF/Cos API to add any type of annotations.
                    AnnotationLowLevelAPI(doc);
                    doc.Save(output_path + "annotation_test1.pdf", SDFDoc.SaveOptions.e_linearized);
                    System.Console.WriteLine("Done. Results saved in annotation_test1.pdf");

                    // An example of using the high-level PDFNet API to read existing annotations,
                    // to edit existing annotations, and to create new annotation from scratch.
                    AnnotationHighLevelAPI(doc);
                    doc.Save(output_path + "annotation_test2.pdf", SDFDoc.SaveOptions.e_linearized);
                    System.Console.WriteLine("Done. Results saved in annotation_test2.pdf");
                }

                // an example of creating various annotations in a brand new document
                using (PDFDoc doc1 = new PDFDoc())
                {
                    CreateTestAnnots(doc1);
                    doc1.Save(output_path + "new_annot_test_api.pdf", SDFDoc.SaveOptions.e_linearized);
                    System.Console.WriteLine("Saved new_annot_test_api.pdf");
                }
            }
            catch (PDFNetException e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The following sample illustrates how to redact a PDF document using 'pdftron.PDF.Redactor'.
        /// </summary>
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";

            try
            {
                ArrayList rarr = new ArrayList();
                rarr.Add(new Redactor.Redaction(1, new Rect(100, 100, 550, 600), false, "Top Secret"));
                rarr.Add(new Redactor.Redaction(2, new Rect(30, 30, 450, 450), true, "Negative Redaction"));
                rarr.Add(new Redactor.Redaction(2, new Rect(0, 0, 100, 100), false, "Positive"));
                rarr.Add(new Redactor.Redaction(2, new Rect(100, 100, 200, 200), false, "Positive"));
                rarr.Add(new Redactor.Redaction(2, new Rect(300, 300, 400, 400), false, ""));
                rarr.Add(new Redactor.Redaction(2, new Rect(500, 500, 600, 600), false, ""));
                rarr.Add(new Redactor.Redaction(3, new Rect(0, 0, 700, 20), false, ""));

                Redactor.Appearance app = new Redactor.Appearance();
                app.RedactionOverlay           = true;
                app.Border                     = false;
                app.ShowRedactedContentRegions = true;

                Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", rarr, app);

                Console.WriteLine("Done...");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 7
0
        private string processOCR(string fileName)
        {
            //PDFNet.Initialize();
            //PDFNet.AddResourceSearchPath("./Lib/");
            PDFNet.SetResourcesPath("./Lib/");
            var s = PDFNet.GetResourcesPath();

            if (!OCRModule.IsModuleAvailable())
            {
                return("MODULE NOT FOUND");
            }
            try
            {
                using (PDFDoc doc = new PDFDoc(fileName))
                {
                    OCROptions opts = new OCROptions();
                    opts.AddLang("eng");
                    string jsonOCRData = OCRModule.GetOCRJsonFromPDF(doc, opts);
                    //string appendedString = getOCRDataFromJson(jsonOCRData);
                    return(jsonOCRData);
                }
                //return appenedString;
            }
            catch (PDFNetException e)
            {
                return(e.Message);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // The first step in every application using PDFNet is to initialize the
            // library and set the path to common PDF resources. The library is usually
            // initialized only once, but calling Initialize() multiple times is also fine.
            PDFNet.Initialize();
            PDFNet.AddResourceSearchPath("../../../../../Lib/");
            if (!CADModule.IsModuleAvailable())
            {
                Console.WriteLine();
                Console.WriteLine("Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.");
                Console.WriteLine("---------------------------------------------------------------");
                Console.WriteLine("The CAD module is an optional add-on, available for download");
                Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
                Console.WriteLine("module, ensure that the SDK is able to find the required files");
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
                Console.WriteLine();
            }

            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/CAD/";
            string output_path = "../../TestFiles/Output/";

            string input_file_name  = "construction drawings color-28.05.18.dwg";
            string output_file_name = "construction drawings color-28.05.18.pdf";

            if (args.Length != 0)
            {
                input_file_name  = args[0];
                output_file_name = input_file_name + ".pdf";
            }

            Console.WriteLine("Example cad:");
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    if (IsRVTFile(input_file_name))
                    {
                        CADConvertOptions opts = new CADConvertOptions();
                        opts.SetPageWidth(800);
                        opts.SetPageHeight(600);
                        opts.SetRasterDPI(150);

                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path + input_file_name, opts);
                    }
                    else
                    {
                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path + input_file_name, null);
                    }
                    pdfdoc.Save(output_path + output_file_name, SDFDoc.SaveOptions.e_remove_unused);
                }

                Console.WriteLine("Done.");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Create a PDF Package.
            try
            {
                using (PDFDoc doc = new PDFDoc())
                {
                    AddPackage(doc, input_path + "numbered.pdf", "My File 1");
                    AddPackage(doc, input_path + "newsletter.pdf", "My Newsletter...");
                    AddPackage(doc, input_path + "peppers.jpg", "An image");
                    AddCovePage(doc);
                    doc.Save(output_path + "package.pdf", SDFDoc.SaveOptions.e_linearized);
                    Console.WriteLine("Done.");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            // Extract parts from a PDF Package.
            try
            {
                using (PDFDoc doc = new PDFDoc(output_path + "package.pdf"))
                {
                    doc.InitSecurityHandler();

                    pdftron.SDF.NameTree files = NameTree.Find(doc, "EmbeddedFiles");
                    if (files.IsValid())
                    {
                        // Traverse the list of embedded files.
                        NameTreeIterator i = files.GetIterator();
                        for (int counter = 0; i.HasNext(); i.Next(), ++counter)
                        {
                            string entry_name = i.Key().GetAsPDFText();
                            Console.WriteLine("Part: {0}", entry_name);
                            FileSpec file_spec = new FileSpec(i.Value());
                            Filter   stm       = file_spec.GetFileData();
                            if (stm != null)
                            {
                                string fname = output_path + "extract_" + counter.ToString() + ".pdf";
                                stm.WriteToFile(fname, false);
                            }
                        }
                    }
                }

                Console.WriteLine("Done.");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 10
0
        public PdfView()
        {
            this.InitializeComponent();

            this.navigationHelper = new NavigationHelper(this);
            PDFNet.Initialize();
            pdfViewCtrl         = new PDFViewCtrl();
            PDFViewBorder.Child = pdfViewCtrl;
            MyToolManager       = new ToolManager(pdfViewCtrl);
        }
        public PdfTronForm()
        {
            InitializeComponent();

            PDFNetLoader loader = PDFNetLoader.Instance();

            PDFNet.SetTempPath("C:\\ProgramData\\ActivePDF\\DocConverter\\Watch Folders\\Default\\Temp");
            PDFNet.Initialize();
            HTML2PDF.SetModulePath(Environment.CurrentDirectory + "\\html2pdf.dll");
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path      = "../../TestFiles/";
            string output_path     = "../../TestFiles/Output/";
            string input_filename  = "newsletter.pdf";
            string output_filename = "newsletter_edited.pdf";

            try
            {
                Console.WriteLine("Opening the input file...");
                using (PDFDoc doc = new PDFDoc(input_path + input_filename))
                {
                    doc.InitSecurityHandler();

                    ElementWriter writer  = new ElementWriter();
                    ElementReader reader  = new ElementReader();
                    XSet          visited = new XSet();

                    PageIterator itr = doc.GetPageIterator();

                    while (itr.HasNext())
                    {
                        try
                        {
                            Page page = itr.Current();
                            visited.Add(page.GetSDFObj().GetObjNum());

                            reader.Begin(page);
                            writer.Begin(page, ElementWriter.WriteMode.e_replacement, false, true, page.GetResourceDict());

                            ProcessElements(reader, writer, visited);
                            writer.End();
                            reader.End();

                            itr.Next();
                        }
                        catch (PDFNetException e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }

                    doc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_remove_unused);
                    Console.WriteLine("Done. Result saved in {0}...", output_filename);
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 13
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            CopyResToFiles();

            PDFNet.Initialize("LICENSE_KEY");

            Locator.CurrentMutable.RegisterConstant <ITextExtractor>(new PdfTronTextExtractor());

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Esempio n. 14
0
        public static Pdf Convert(string path, bool savePdfStructureAsXml = false, string xmlName = "pdf.xml")
        {
            PDFNet.Initialize();
            using (var doc = new PDFDoc(path))
            {
                var result = new XDocument(new XElement("Pdf"));

                for (int i = 1; i <= doc.GetPageCount(); i++)
                {
                    var page = doc.GetPage(i);
                    using (var txt = new TextExtractor())
                    {
                        txt.Begin(page);
                        var text = txt.GetAsXML(TextExtractor.XMLOutputFlags.e_words_as_elements | TextExtractor.XMLOutputFlags.e_output_bbox);

                        //combine words within a line (we don't need their position)
                        var xml   = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(text)));
                        var lines = xml.Root.DescendantsAndSelf().Where(s => s.Name == "Line").ToArray();
                        foreach (var line in lines)
                        {
                            var t = String.Join(" ", line.DescendantsAndSelf("Word").Select(s => s.Value));
                            line.RemoveNodes();
                            line.SetValue(t);
                        }
                        result.Root.Add(xml.Root);
                    }
                }

                //save the temporary xml just for debug purposes
                if (savePdfStructureAsXml)
                {
                    var destinationPath = Path.GetDirectoryName(path) + xmlName;
                    using (var writer = new XmlTextWriter(destinationPath, null))
                    {
                        writer.Formatting = Formatting.Indented;
                        result.Save(writer);
                    }
                }

                using (var ms = new MemoryStream())
                {
                    result.Save(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    var serializer = new XmlSerializer(typeof(Pdf));
                    return((Pdf)serializer.Deserialize(ms));
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            CopyResToFiles();

            PDFNet.Initialize(this, Resource.Raw.pdfnet, "LICENSE_KEY");

            Locator.CurrentMutable.RegisterConstant <ITextExtractor>(new PdfTronTextExtractor());

            LoadApplication(new App());
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();
            PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms);              // Required for PDFA validation.

            //-----------------------------------------------------------
            // Example 1: PDF/A Validation
            //-----------------------------------------------------------
            try
            {
                string filename = "newsletter.pdf";
                using (PDFACompliance pdf_a = new PDFACompliance(false, input_path + filename, null, PDFACompliance.Conformance.e_Level1B, null, 10, false))
                {
                    PrintResults(pdf_a, filename);
                }
            }
            catch (pdftron.Common.PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //-----------------------------------------------------------
            // Example 2: PDF/A Conversion
            //-----------------------------------------------------------
            try
            {
                string filename = "fish.pdf";
                using (PDFACompliance pdf_a = new PDFACompliance(true, input_path + filename, null, PDFACompliance.Conformance.e_Level1B, null, 10, false))
                {
                    filename = "pdfa.pdf";
                    pdf_a.SaveAs(output_path + filename, true);
                }

                // Re-validate the document after the conversion...
                filename = "pdfa.pdf";
                using (PDFACompliance pdf_a = new PDFACompliance(false, output_path + filename, null, PDFACompliance.Conformance.e_Level1B, null, 10, false))
                {
                    PrintResults(pdf_a, filename);
                }
            }
            catch (pdftron.Common.PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("PDFACompliance test completed.");
        }
        static void SignPDF()
        {
            PDFNet.Initialize();
            // Create a page
            using (var doc = new PDFDoc()) {
                var page = doc.PageCreate(new Rect(0, 0, 595, 842));
                page.SetRotation(Page.Rotate.e_0);
                page.SetCropBox(new Rect(0, 0, 595, 842));
                doc.PagePushBack(page);

                var rect    = new Rect(0, 0, 0, 0);
                var fieldId = Guid.NewGuid().ToString();

                var fieldToSign         = doc.FieldCreate(fieldId, Field.Type.e_signature);
                var signatureAnnotation = Widget.Create(doc, rect, fieldToSign);

                signatureAnnotation.SetFlag(Annot.Flag.e_print, true);
                signatureAnnotation.SetPage(page);
                var widgetObj = signatureAnnotation.GetSDFObj();
                widgetObj.PutNumber("F", 132.0);
                widgetObj.PutName("Type", "Annot");

                page.AnnotPushBack(signatureAnnotation);

                //Create the signature handler
                var sigHandler = new RemoteSignatureTimeStampPdfHandler(new HttpClient());

                //Add handler to PDFDoc instance
                var sigHandlerId = doc.AddSignatureHandler(sigHandler);

                // Add the SignatureHandler instance to PDFDoc, making sure to keep track of it using the ID returned.
                var sigDict = fieldToSign.UseSignatureHandler(sigHandlerId);

                var signatureObject = signatureAnnotation.GetSDFObj();

                var cultureInfo = new CultureInfo("en-US");
                var gmt1Date    = DateTime.Now;

                var value = gmt1Date.ToString("'D:'yyyyMMddHHmmsszzz", cultureInfo);

                // Add signing date
                sigDict.PutString("M", value);

                doc.Save(SDFDoc.SaveOptions.e_incremental);
            }
        }
Esempio n. 18
0
        protected async override void OnNavigatedFrom(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedFrom(e);

            if (e.NavigationMode == NavigationMode.Back && pdfDoc != null)
            {
                MessageDialog dialog = new MessageDialog("Sollen mögliche Änderungen gespeichert werden?", "Warnung");
                dialog.Commands.Add(new UICommand("Ja", command =>
                {
                    OverwriteOldDocument();
                }));
                dialog.Commands.Add(new UICommand("Nain"));
                await dialog.ShowAsync();
            }

            PDFNet.Terminate();
        }
        static void Main(string[] args)
        {
            try
            {
                PDFNet.Initialize();

                Console.WriteLine("-------------------------------------------------");
                Console.WriteLine("Extract page element information from all ");
                Console.WriteLine("pages in the document.");

                // Open the test file
                using (PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf"))
                {
                    doc.InitSecurityHandler();

                    int          pgnum = doc.GetPageCount();
                    PageIterator itr;

                    using (ElementReader page_reader = new ElementReader())
                    {
                        for (itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())                                    //  Read every page
                        {
                            Console.WriteLine("Page {0:d}----------------------------------------",
                                              itr.GetPageNumber());

                            Rect crop_box = itr.Current().GetCropBox();
                            crop_box.Normalize();

                            // Console.WriteLine(" Page Rectangle: x={0:f} y={1:f} x2={2:f} y2={3:f}", crop_box.x1, crop_box.y1, crop_box.x2, crop_box.y2);
                            // Console.WriteLine(" Page Size: width={0:f} height={1:f}", crop_box.Width(), crop_box.Height());

                            page_reader.Begin(itr.Current());
                            ProcessElements(page_reader);
                            page_reader.End();
                        }
                    }

                    Console.WriteLine("Done.");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 20
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Instance = this;
            global::Xamarin.Forms.Forms.Init(this, bundle);

            try
            {
                pdftron.PDF.Tools.Utils.AppUtils.InitializePDFNetApplication(this);
                Console.WriteLine(PDFNet.GetVersion());
            }
            catch (pdftron.Common.PDFNetException e)
            {
                Console.WriteLine(e.GetMessage());
                return;
            }

            LoadApplication(new App());
        }
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Sample 1:
            // Directly convert from PDF to XOD.
            pdftron.PDF.Convert.ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod");

            // Sample 2:
            // Directly convert from generic XPS to XOD.
            pdftron.PDF.Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod");

            // Sample 3:
            // Convert from MS Office (does not require printer driver for Office 2007+)
            // and other document formats to XOD.
            BulkConvertRandomFilesToXod();

            Console.WriteLine("Done.");
        }
Esempio n. 22
0
        public MainViewModel()
        {
            // Initilizes PDFNet
            PDFNet.Initialize();

            // Make sure to Terminate any processes
            Application.Current.SessionEnding += Current_SessionEnding;

            // Init all Commands
            CMDOpenDocument   = new Relaycommand(OpenDocument);
            CMDNextPage       = new Relaycommand(NextPage);
            CMDPreviousPage   = new Relaycommand(PreviousPage);
            CMDAnottateText   = new Relaycommand(AddTextSample);
            CMDFreeTextSample = new Relaycommand(AddFreeTextSample);
            CMDSelectText     = new Relaycommand(SelectText);
            CMDExit           = new Relaycommand(ExitApp);
            CMDZoomIn         = new Relaycommand(ZoomIn);
            CMDZoomOut        = new Relaycommand(ZoomOut);
            CMDUndo           = new Relaycommand(Undo);
            CMDRedo           = new Relaycommand(Redo);

            // Checks the scale factor to determine the right resolution
            PresentationSource source      = PresentationSource.FromVisual(Application.Current.MainWindow);
            double             scaleFactor = 1;

            if (source != null)
            {
                scaleFactor = 1 / source.CompositionTarget.TransformFromDevice.M11;
            }

            // Set working doc to Viewer
            PDFViewer = new PDFViewWPF();
            PDFViewer.PixelsPerUnitWidth = scaleFactor;

            // PDF Viewer Events subscription
            PDFViewer.MouseLeftButtonDown += PDFView_MouseLeftButtonDown;

            // Enable access to the Tools available
            _toolManager = new ToolManager(PDFViewer);
            _toolManager.AnnotationAdded   += _toolManager_AnnotationAdded;
            _toolManager.AnnotationRemoved += _toolManager_AnnotationRemoved;
        }
Esempio n. 23
0
        public string Test()
        {
            string s = "";

            // Initialize PDFNet before using any PDFTron related
            // classes and methods (some exceptions can be found in API)
            PDFNet.Initialize();

            // Using PDFNet related classes and methods, must
            // catch or throw PDFNetException
            try
            {
                string input_path = "./TestFiles/";
                s = processOCR(input_path + "discharge-summary.pdf");

                return(s);
            }
            catch (PDFNetException e)
            {
                return(e.Message);
            }
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            try
            {
                using (PDFDoc doc = new PDFDoc())
                {
                    Page page = doc.PageCreate();
                    doc.PagePushBack(page);
                    Obj annots = doc.CreateIndirectArray();
                    page.GetSDFObj().Put("Annots", annots);

                    Create3DAnnotation(doc, annots);
                    doc.Save(output_path + "dice_u3d.pdf", SDFDoc.SaveOptions.e_linearized);
                }
                Console.WriteLine("Done");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();
            Boolean err = false;

            err = ConvertToPdfFromFile();
            if (err)
            {
                Console.WriteLine("ConvertFile failed");
            }
            else
            {
                Console.WriteLine("ConvertFile succeeded");
            }

            err = ConvertSpecificFormats();
            if (err)
            {
                Console.WriteLine("ConvertSpecificFormats failed");
            }
            else
            {
                Console.WriteLine("ConvertSpecificFormats succeeded");
            }

            err = ConvertToXpsFromFile();
            if (err)
            {
                Console.WriteLine("ConvertToXpsFromFile failed");
            }
            else
            {
                Console.WriteLine("ConvertToXpsFromFile succeeded");
            }

            Console.WriteLine("Done.");
        }
Esempio n. 26
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            try
            {
                // first the one-line conversion method
                SimpleConvert("simple-word_2007.docx", "simple-word_2007.pdf");

                // then the more flexible line-by-line conversion API
                FlexibleConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf");
            }
            catch (pdftron.Common.PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unrecognized Exception: " + e.Message);
            }

            PDFNet.Terminate();
            Console.WriteLine("Done.");
        }
Esempio n. 27
0
        public MainWindow()
        {
            InitializeComponent();

            PDFNet.Initialize();
        }
 static OfficeConverter()
 {
     PDFNetLoader.Instance();
     PDFNet.Initialize();
 }
Esempio n. 29
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();
            try
            {
                using (PDFDoc doc = new PDFDoc())
                    using (ElementWriter writer = new ElementWriter())
                        using (ElementBuilder eb = new ElementBuilder())
                        {
                            // The following sample illustrates how to create and use tiling patterns
                            Page page = doc.PageCreate();
                            writer.Begin(page);

                            Element element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1);
                            writer.WriteElement(element);              // Begin the text block

                            element = eb.CreateTextRun("G");
                            element.SetTextMatrix(720, 0, 0, 720, 20, 240);
                            GState gs = element.GetGState();
                            gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text);
                            gs.SetLineWidth(4);

                            // Set the fill color space to the Pattern color space.
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateTilingPattern(doc));

                            writer.WriteElement(element);
                            writer.WriteElement(eb.CreateTextEnd()); // Finish the text block

                            writer.End();                            // Save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            /// The following sample illustrates how to create and use image tiling pattern
                            page = doc.PageCreate();
                            writer.Begin(page);

                            eb.Reset();
                            element = eb.CreateRect(0, 0, 612, 794);

                            // Set the fill color space to the Pattern color space.
                            gs = element.GetGState();
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateImageTilingPattern(doc));
                            element.SetPathFill(true);

                            writer.WriteElement(element);

                            writer.End();               // Save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            /// The following sample illustrates how to create and use PDF shadings
                            page = doc.PageCreate();
                            writer.Begin(page);

                            eb.Reset();
                            element = eb.CreateRect(0, 0, 612, 794);

                            // Set the fill color space to the Pattern color space.
                            gs = element.GetGState();
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateAxialShading(doc));
                            element.SetPathFill(true);

                            writer.WriteElement(element);

                            writer.End();               // save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused);
                            Console.WriteLine("Done. Result saved in patterns.pdf...");
                        }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";

            try
            {
                Console.WriteLine("-------------------------------------------------");
                Console.WriteLine("Opening the input pdf...");
                using (PDFDoc in_doc = new PDFDoc(input_path + "newsletter.pdf"))
                {
                    in_doc.InitSecurityHandler();

                    // Create a list of pages to import from one PDF document to another.
                    ArrayList import_list = new ArrayList();
                    for (PageIterator itr = in_doc.GetPageIterator(); itr.HasNext(); itr.Next())
                    {
                        import_list.Add(itr.Current());
                    }

                    using (PDFDoc new_doc = new PDFDoc())                     //  Create a new document
                        using (ElementBuilder builder = new ElementBuilder())
                            using (ElementWriter writer = new ElementWriter())
                            {
                                ArrayList imported_pages = new_doc.ImportPages(import_list);

                                // Paper dimension for A3 format in points. Because one inch has
                                // 72 points, 11.69 inch 72 = 841.69 points
                                Rect   media_box = new Rect(0, 0, 1190.88, 841.69);
                                double mid_point = media_box.Width() / 2;

                                for (int i = 0; i < imported_pages.Count; ++i)
                                {
                                    // Create a blank new A3 page and place on it two pages from the input document.
                                    Page new_page = new_doc.PageCreate(media_box);
                                    writer.Begin(new_page);

                                    // Place the first page
                                    Page    src_page = (Page)imported_pages[i];
                                    Element element  = builder.CreateForm(src_page);

                                    double sc_x  = mid_point / src_page.GetPageWidth();
                                    double sc_y  = media_box.Height() / src_page.GetPageHeight();
                                    double scale = Math.Min(sc_x, sc_y);
                                    element.GetGState().SetTransform(scale, 0, 0, scale, 0, 0);
                                    writer.WritePlacedElement(element);

                                    // Place the second page
                                    ++i;
                                    if (i < imported_pages.Count)
                                    {
                                        src_page = (Page)imported_pages[i];
                                        element  = builder.CreateForm(src_page);
                                        sc_x     = mid_point / src_page.GetPageWidth();
                                        sc_y     = media_box.Height() / src_page.GetPageHeight();
                                        scale    = Math.Min(sc_x, sc_y);
                                        element.GetGState().SetTransform(scale, 0, 0, scale, mid_point, 0);
                                        writer.WritePlacedElement(element);
                                    }

                                    writer.End();
                                    new_doc.PagePushBack(new_page);
                                }
                                new_doc.Save(output_path + "newsletter_booklet.pdf", SDFDoc.SaveOptions.e_linearized);
                                Console.WriteLine("Done. Result saved in newsletter_booklet.pdf...");
                            }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught:\n{0}", e);
            }
        }