static void Main(string[] args)
        {
            string inputFile = @".\sample2.pdf";

            // Create Bytescout.PDFExtractor.TextExtractor instance
            TextExtractor extractor = new TextExtractor();

            extractor.RegistrationName = "demo";
            extractor.RegistrationKey  = "demo";

            // Load sample PDF document
            extractor.LoadDocumentFromFile(inputFile);

            int pageCount = extractor.GetPageCount();

            // Search each page for a keyword
            for (int i = 0; i < pageCount; i++)
            {
                if (extractor.Find(i, "bombardment", false))
                {
                    // Extract page
                    using (DocumentSplitter splitter = new DocumentSplitter("demo", "demo"))
                    {
                        splitter.OptimizeSplittedDocuments = true;

                        int    pageNumber = i + 1; // (!) page number in ExtractPage() is 1-based
                        string outputFile = @".\page" + pageNumber + ".pdf";
                        splitter.ExtractPage(inputFile, outputFile, pageNumber);

                        Console.WriteLine("Extracted page " + pageNumber + " to file \"" + outputFile + "\"");
                    }
                }
            }

            // Cleanup
            extractor.Dispose();

            Console.WriteLine();
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            string inputFile = @".\sample.pdf";

            using (DocumentSplitter splitter = new DocumentSplitter("demo", "demo"))
            {
                splitter.OptimizeSplittedDocuments = true;

                // Extracting specific page:
                // =========================

                splitter.ExtractPage(inputFile, "page3.pdf", 3); // (!) Note: page number is 1-based.

                Console.WriteLine(@"Extracted page 3 to file ""page3.pdf""");
                Console.WriteLine();

                // Split in two parts:
                // ===================

                splitter.Split(inputFile, "part1.pdf", "part2.pdf", 3); // (!) Note: page number is 1-based.

                Console.WriteLine(@"Splitted at page 3 to files ""part1.pdf"" and ""part2.pdf""");
                Console.WriteLine();

                // Split by ranges:
                // ================

                string[] files = splitter.Split(inputFile, "1-3,4-6,7,8-"); // (!) Note: page numbers are 1-based; ending "-" means "to the end".

                Console.WriteLine(@"Splitted by ranges: ");
                foreach (string file in files)
                {
                    Console.WriteLine("    " + Path.GetFileName(file));
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }