예제 #1
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!");
        }
예제 #2
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!");
        }
예제 #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 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!");
        }
예제 #4
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!");
        }
예제 #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 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!");
        }