static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath))
            {
                // Get the page count of the PDF
                int result = toolkit.OpenInputFile(
                    InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the rotation of the page
                    // Note: there is no need to open an input file as NumPages
                    // opened the PDF
                    result = toolkit.GetInputPageRotation(PageNumber: 1);
                    Console.WriteLine($"Page Rotation: {result}");

                    // Close the input file
                    toolkit.CloseInputFile();

                    // Load the page 1 details of the PDF
                    toolkit.GetBoundingBox(
                        FileName: $"{strPath}Toolkit.Input.pdf", PageNbr: 1);

                    // Get the Page Width and Height for page one
                    Console.WriteLine($"Page Width: {toolkit.BoundingBoxWidth}");
                    Console.WriteLine($"Page Height: {toolkit.BoundingBoxHeight}");

                    // Get the top left coordinates of the bounding box
                    Console.WriteLine($"Page Top Left Coordinates: {toolkit.BoundingBoxLeft}, {toolkit.BoundingBoxTop}");

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.RedactAllImages.pdf");
                if (result == 0)
                {
                    // Get the Redactor object from Toolkit
                    APToolkitNET.Redactor redactor = toolkit.GetRedactor();

                    // Open the input PDF
                    result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                    if (result == 0)
                    {
                        // Redact all images from the input file.
                        redactor.RedactAll(mode: APToolkitNET.Redactor.RedactionMode.AllImages);

                        // Call the Redactor Apply method to execute the
                        // redaction process. All Toolkit methods normally
                        // called between OpenInputFile and CopyForm
                        // (PrintText, PrintImage etc.) must be after
                        // Redactor.Apply
                        redactor.Apply();

                        result = toolkit.CopyForm(FirstPage: 0, LastPage: 0);
                        if (result != 1)
                        {
                            WriteResult("CopyForm Failed", toolkit);
                        }

                        // Close the new file to complete PDF creation
                        toolkit.CloseInputFile();
                    }
                    else
                    {
                        WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                        return;
                    }
                }
                else
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #3
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath))
            {
                // Specify the file to retrieve information about
                toolkit.GetPDFInfo(FileName: $"{strPath}Toolkit.Input.pdf");

                // Retrieve various information about the PDF
                Console.WriteLine($"Author: {toolkit.Author}");
                Console.WriteLine($"Title: {toolkit.Title}");
                Console.WriteLine($"Subject: {toolkit.Subject}");
                Console.WriteLine($"Keywords: {toolkit.Keywords}");
                Console.WriteLine($"Producer: {toolkit.Producer}");
                Console.WriteLine($"Creator: {toolkit.Creator}");
                Console.WriteLine($"Creation Date: {toolkit.CreateDate}");
                Console.WriteLine($"Modification Date: {toolkit.ModDate}");

                // Close the new file to complete PDF creation
                toolkit.CloseInputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #4
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit())
            {
                // Specify the file to retrieve information about
                toolkit.GetPDFInfo($"{strPath}Toolkit.Input.pdf");

                // Retrieve various information about the PDF
                Console.WriteLine($"Author: {toolkit.Author}");
                Console.WriteLine($"Title: {toolkit.Title}");
                Console.WriteLine($"Subject: {toolkit.Subject}");
                Console.WriteLine($"Keywords: {toolkit.Keywords}");
                Console.WriteLine($"Producer: {toolkit.Producer}");
                Console.WriteLine($"Creator: {toolkit.Creator}");
                Console.WriteLine($"Creation Date: {toolkit.CreateDate}");
                Console.WriteLine($"Modification Date: {toolkit.ModDate}");

                // Close the new file to complete PDF creation
                toolkit.CloseInputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #5
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Redactor object from Toolkit
                APToolkitNET.Redactor redactor = toolkit.GetRedactor();

                int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.RedactRegExPreset.pdf");
                if (result == 0)
                {
                    // Open the input PDF
                    result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                    if (result == 0)
                    {
                        // Redactor has several pre generated regular
                        // expressions for text redaction. (date, email,
                        // numbers, phone number, SSN, USD, websites, words)
                        // You may also redact individual pages setting the
                        // page function argument, the default is all pages.
                        redactor.RedactRegexPreset(regexpreset: APToolkitNET.RegexPresets.Preset.RegexPhoneNumber);

                        result = toolkit.CopyForm(FirstPage: 0, LastPage: 0);
                        if (result != 1)
                        {
                            WriteResult("CopyForm Failed", toolkit);
                        }

                        // Close the new file to complete PDF creation
                        toolkit.CloseInputFile();
                    }
                    else
                    {
                        WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                        return;
                    }
                }
                else
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #6
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Open the input PDF
                short result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the input document page count.
                    int pageCount = toolkit.NumPages("");

                    // Get the Redactor object from Toolkit
                    APToolkitNET.Rasterizer rasterizer = toolkit.GetRasterizer();

                    // Rotate the image files 90 degrees
                    rasterizer.Rotation = 90.0f;

                    for (int currentPage = 1; currentPage <= pageCount; currentPage++)
                    {
                        string outputFile = $"{strPath}RotateImage.{currentPage}.jpg";

                        // Convert each page of the input PDF to an image rotated 90 degrees.
                        if (!rasterizer.ToImage(sFileName: $"{outputFile}", eImageType: APToolkitNET.APImageType.JPEG, currentPage))
                        {
                            WriteResult($"Error writing image file to: {outputFile}", toolkit);
                        }
                        else
                        {
                            Console.WriteLine($"Creating image file: {outputFile}");
                        }
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit())
            {
                // Get the page count of the PDF
                int result = toolkit.OpenInputFile(
                    FileName: $"{strPath}Toolkit.Input.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }

                // Get the rotation of the page
                // Note: there is no need to open an input file as NumPages
                // opened the PDF
                result = toolkit.GetInputPageRotation(PageNumber: 1);
                Console.WriteLine($"Page Rotation: {result}");

                // Close the input file
                toolkit.CloseInputFile();

                // Load the page 1 details of the PDF
                toolkit.GetBoundingBox(
                    FileName: $"{strPath}Toolkit.Input.pdf", PageNbr: 1);

                // Get the Page Width and Height for page one
                Console.WriteLine($"Page Width: {toolkit.BoundingBoxWidth}");
                Console.WriteLine($"Page Height: {toolkit.BoundingBoxHeight}");

                // Get the top left coordinates of the bounding box
                Console.WriteLine($"Page Top Left Coordinates: {toolkit.BoundingBoxLeft}, {toolkit.BoundingBoxTop}");

                // Close the new file to complete PDF creation
                toolkit.CloseInputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #8
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Extractor object from Toolkit
                APToolkitNET.Extractor extractor = toolkit.GetExtractor();

                // Open the input PDF
                int result = toolkit.OpenInputFile($"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Extract all images from the input PDF and save them in a
                    // randomly named file.
                    // Extractor supports BMP, JPEG, PNG, RGB, and TIFF
                    var images = extractor.ExtractImages(APToolkitNET.APImageType.JPEG);
                    Parallel.ForEach(images, (image) =>
                    {
                        string fileName = $"{System.IO.Path.GetRandomFileName()}.jpg";
                        try
                        {
                            Console.WriteLine($"Extracting Image to: {fileName}");
                            System.IO.File.WriteAllBytes(
                                $"{strPath}\\{fileName}",
                                image);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Exception caught creating image file ({fileName}): {e.Message}");
                        }
                    });

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #9
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Extractor object from Toolkit
                APToolkitNET.Extractor extractor = toolkit.GetExtractor();

                // Open the input PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the number of pages in the input PDF.
                    int numPages = toolkit.NumPages(FileName: "");

                    // Find the coordinates, width, and height of all instances
                    // of the search text in the document. You may also use a
                    //regular expression as the search input.
                    APToolkitNET.APRectangle[] locations =
                        extractor.FindText(Text: "Toolkit");

                    foreach (var location in locations)
                    {
                        Console.WriteLine($"Search String Located.");
                        Console.WriteLine($"\tPage: {location.Page}");
                        Console.WriteLine($"\tWidth: {location.Location.Width}");
                        Console.WriteLine($"\tHeight: {location.Location.Height}");
                        Console.WriteLine($"\tCoordinates: {location.Location.X}, {location.Location.Y}");
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #10
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit())
            {
                // Here you can place any code that will alter the output file
                // such as adding security, setting page dimensions, etc.

                // Create the new PDF file
                int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.PDFViewData.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }

                // Open the template PDF
                result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }

                // Get the reference to the InitialViewInfo object
                APToolkitNET.InitialViewInfo viewInfo = toolkit.GetInitialViewInfo();

                // Options for viewer window
                Console.WriteLine($"Center Window: {viewInfo.CenterWindow}");
                Console.WriteLine($"Full Screen: {viewInfo.FullScreen}");
                Console.WriteLine($"Resize Window: {viewInfo.ResizeWindow}");
                Console.WriteLine($"Show: {viewInfo.Show}");

                // Show or hide UI elements of the viewer
                Console.WriteLine($"Hide Menu Bar: {viewInfo.HideMenuBar}");
                Console.WriteLine($"Hide Tool Bars: {viewInfo.HideToolBars}");
                Console.WriteLine($"Hide Window Controls: {viewInfo.HideWindowControls}");
                Console.WriteLine($"Navigation Tab: {viewInfo.NavigationTab}");

                // Page settings
                Console.WriteLine($"Magnification: {viewInfo.Magnification}");
                Console.WriteLine($"Open To Page: {viewInfo.OpenToPage}");
                Console.WriteLine($"Page Layout: {viewInfo.PageLayout}");

                // Close the input file
                toolkit.CloseInputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #11
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Spooler object from Toolkit
                APToolkitNET.Spooler spooler = toolkit.GetSpooler();

                // Open the input PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Set the duplex mode, only valid if supported by the
                    // printer.
                    spooler.DuplexMode = APToolkitNET.DuplexMode.Vertical;

                    // Set the printer name
                    spooler.PrinterName = @"\\ap-dc-02\Ops - Brother HL-6180DW";

                    // Set the number of copies to print
                    spooler.Copies = 2;

                    result = spooler.PrintFile();
                    if (result != 0)
                    {
                        WriteResult($"Error printing PDF: {result}", toolkit);
                        return;
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #12
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath))
            {
                // Open the template PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the reference to the InitialViewInfo object
                    APToolkitNET.InitialViewInfo viewInfo = toolkit.GetInitialViewInfo();

                    // Options for viewer window
                    Console.WriteLine($"Center Window: {viewInfo.CenterWindow}");
                    Console.WriteLine($"Full Screen: {viewInfo.FullScreen}");
                    Console.WriteLine($"Resize Window: {viewInfo.ResizeWindow}");
                    Console.WriteLine($"Show: {viewInfo.Show}");

                    // Show or hide UI elements of the viewer
                    Console.WriteLine($"Hide Menu Bar: {viewInfo.HideMenuBar}");
                    Console.WriteLine($"Hide Tool Bars: {viewInfo.HideToolBars}");
                    Console.WriteLine($"Hide Window Controls: {viewInfo.HideWindowControls}");
                    Console.WriteLine($"Navigation Tab: {viewInfo.NavigationTab}");

                    // Page settings
                    Console.WriteLine($"Magnification: {viewInfo.Magnification}");
                    Console.WriteLine($"Open To Page: {viewInfo.OpenToPage}");
                    Console.WriteLine($"Page Layout: {viewInfo.PageLayout}");

                    // Close the input file
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #13
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Extractor object from Toolkit
                APToolkitNET.Extractor extractor = toolkit.GetExtractor();

                // Open the input PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the number of pages in the input PDF.
                    int numPages = toolkit.NumPages(FileName: "");

                    // If you know where on the page you want to look, you can
                    // restrict extractions to just that area. In this example,
                    // we'll just a square 200 units  on each side and pull
                    // from roughly the middle of the page.
                    string extractedText = extractor.ExtractTextByArea(
                        Page: 1,
                        Rect: new System.Drawing.RectangleF(10.0f, 200.0f, 200.0f, 200.0f));

                    Console.WriteLine($"Extracted Text: {extractedText}");

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #14
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Extractor object from Toolkit
                APToolkitNET.Extractor extractor = toolkit.GetExtractor();

                // Open the input PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Simple regex to search for all words starting with an "S"
                    Regex re = new Regex(pattern: @"\bs\S*");

                    // Count instances on just the first page.
                    string[] searchResults =
                        extractor.ExtractByRegex(re: re, Page: 1);
                    Console.WriteLine($"{searchResults.Count()} instances found on page 1");
                    foreach (string searchResult in searchResults)
                    {
                        Console.WriteLine($"\t{searchResult}");
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #15
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath))
            {
                // Open the template PDF
                short result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }

                // List the fields in the input PDF
                APToolkitNET.InputFields inputFields = toolkit.GetInputFields();
                foreach (APToolkitNET.FieldInstances fieldInstances in inputFields.Instances)
                {
                    foreach (APToolkitNET.FieldInfo fieldInstance in fieldInstances.Fields)
                    {
                        WriteFieldInfo(FieldInfo: fieldInstance);
                    }
                }

                // Close the input file
                toolkit.CloseInputFile();
            }

            WriteResult("Success!");
        }
        public ActionResult <Response> CreateSampleBookmarks([FromBody] Request request)
        {
            try
            {
                using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit())
                {
                    //Set page dimensions
                    toolkit.OutputPageHeight = 792.0f;
                    toolkit.OutputPageWidth  = 612.0f;

                    //Create new file
                    int result = toolkit.OpenOutputFile(FileName: $"{serverDirectory}SampleBookmarks.pdf");
                    if (result != 0)
                    {
                        throw new Exception($"Could not create destination file: SampleBookmarks.pdf");
                    }

                    // Open Source File
                    result = toolkit.OpenInputFile($"{ serverDirectory}{request.filename}.pdf");
                    if (result != 0)
                    {
                        throw new Exception($"Could not Open file: {request.filename}");
                    }

                    // Add new page to output
                    toolkit.NewPage();
                    toolkit.SetFont(FontName: "Arial", FontSize: 20);
                    toolkit.PrintText(X: 72.0f, Y: 720.0f, Text: "Table of Contents");
                    toolkit.AddInternalLink(1, 72, 720, 72, 720, 5, 72, 720, 4);

                    //toolkit.AddInternalLinkBookmark("Section 1", 2, 0, 0);

                    APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager();
                    bookmarkManager.CopyBookmarks = true;
                    APToolkitNET.Bookmark root = bookmarkManager.MakeRoot("Table of Contents", "red", APToolkitNET.FontStyle.Bold);

                    var section1 = bookmarkManager.AddChild(root, "Section 1");
                    section1.SetInternalLink(1, 0, 0);
                    var section11 = bookmarkManager.AddChild(section1, "Section 1.1");
                    section11.SetInternalLink(2, 0, 0);
                    var section111 = bookmarkManager.AddChild(section1, "Section 1.1.1");
                    section11.SetInternalLink(3, 0, 0);

                    var section2 = bookmarkManager.AddChild(root, "Section 2");
                    section2.SetInternalLink(4, 0, 0);
                    var section21 = bookmarkManager.AddChild(section2, "Section 2.1");
                    section21.SetInternalLink(5, 0, 0);
                    var section211 = bookmarkManager.AddChild(section2, "Section 2.1.1");
                    section211.SetInternalLink(6, 0, 0);

                    // Close the new file to complete PDF creation
                    toolkit.CopyForm(0, 0);
                    toolkit.CloseInputFile();
                    toolkit.CloseOutputFile();

                    return(new Response()
                    {
                        FileContent = string.Empty,
                        FileName = "SampleBookmarks.pdf",
                        Message = "File SampleBookmarks.pdf created successfully",
                        Success = true
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "",
                    Message = "Could not Create Sample Bookmarks " + ex.Message,
                    Success = false
                });
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            string strPath   = System.AppDomain.CurrentDomain.BaseDirectory;
            string inputFile = $"{strPath}Toolkit.Input.pdf";

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Retrieves the number of pages for the specified PDF file.
                int numPages = toolkit.NumPages(inputFile);
                if (numPages == 0)
                {
                    WriteResult($"Error getting input file page count: {numPages.ToString()}", toolkit);
                    return;
                }

                // The number of pages from the input PDF to place per row.
                float pagesPerRow = Convert.ToSingle(Math.Ceiling(Math.Sqrt((double)numPages)));

                // Close the input file before creating a new document.
                toolkit.CloseInputFile();

                // Create the new PDF file
                int result = toolkit.OpenOutputFile($"{strPath}Toolkit.StitchPDF.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }

                // Using the default PDF width and height of 612/792
                float pageWidth = 612.0f, pageHeight = 792.0f;

                // The width and height of each page from the original PDF
                // added to the output file.
                float width = pageWidth / pagesPerRow, height = pageHeight / pagesPerRow;

                // The rows of images from the original PDF added to the new
                // document.
                int numRows = Convert.ToInt32(Math.Ceiling(pageHeight / height));

                for (int i = 1; i < numRows; ++i)
                {
                    for (int j = 0; j < pagesPerRow; ++j)
                    {
                        // Add the page from the original PDF to the output.
                        toolkit.StitchPDF(
                            FileName: inputFile,
                            PageNumber: i + j,
                            X: width * j,
                            Y: pageHeight - (height * i),
                            Width: width,
                            Height: height,
                            Rotation: 0);
                    }
                }

                // Close the new file to complete PDF creation
                toolkit.CloseOutputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #18
0
        static void Main(string[] args)
        {
            string strPath   = System.AppDomain.CurrentDomain.BaseDirectory;
            string inputFile = $"{strPath}Toolkit.Input.pdf";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit())
            {
                // Retrieves the number of pages for the specified PDF file.
                int numPages = toolkit.NumPages(inputFile);
                if (numPages == 0)
                {
                    WriteResult($"Error getting input file page count: {numPages.ToString()}", toolkit);
                    return;
                }

                // The number of pages from the input PDF to place per row.
                float pagesPerRow = Convert.ToSingle(Math.Ceiling(Math.Sqrt((double)numPages)));

                // Close the input file before creating a new document.
                toolkit.CloseInputFile();

                // Create the new PDF file
                int result = toolkit.OpenOutputFile($"{strPath}Toolkit.StitchPDF.pdf");
                if (result != 0)
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }

                // Using the default PDF width and height of 612/792
                float pageWidth = 612.0f, pageHeight = 792.0f;

                // The width and height of each page from the original PDF
                // added to the output file.
                float width = pageWidth / pagesPerRow, height = pageHeight / pagesPerRow;

                // The rows of images from the original PDF added to the new
                // document.
                int numRows = Convert.ToInt32(Math.Ceiling(pageHeight / height));

                for (int i = 1; i < numRows; ++i)
                {
                    for (int j = 0; j < pagesPerRow; ++j)
                    {
                        // Add the page from the original PDF to the output.
                        toolkit.StitchPDF(
                            FileName: inputFile,
                            PageNumber: i + j,
                            X: width * j,
                            Y: pageHeight - (height * i),
                            Width: width,
                            Height: height,
                            Rotation: 0);
                    }
                }

                // Close the new file to complete PDF creation
                toolkit.CloseOutputFile();
            }

            // Process Complete
            WriteResult("Success!");
        }
Пример #19
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Get the Extractor object from Toolkit
                APToolkitNET.Extractor extractor = toolkit.GetExtractor();

                // Open the input PDF
                int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Extract the text from the whole document at once.
                    string extractedText = extractor.ExtractText();

                    string fileName = $"{System.IO.Path.GetRandomFileName()}.txt";
                    try
                    {
                        if (extractedText.Length != 0)
                        {
                            Console.WriteLine($"Writing full document text to: {fileName}");
                            System.IO.File.WriteAllText(
                                $"{System.IO.Directory.GetCurrentDirectory()}\\{fileName}",
                                extractedText);

                            // Get the number of pages in the input PDF
                            int numPages = toolkit.NumPages("");

                            // Extract Text by Page
                            for (int i = 1; i <= numPages; i++)
                            {
                                fileName      = $"{System.IO.Path.GetRandomFileName()}_Page{i}.txt";
                                extractedText = extractor.ExtractText(i);
                                System.IO.File.WriteAllText(
                                    $"{strPath}\\{fileName}",
                                    extractedText);
                            }
                        }
                        else
                        {
                            Console.WriteLine("No text found in document.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Exception caught creating image file ({fileName}): {e.Message}");
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }