ByteScout PDF Extractor SDK - C# - Find Keyword And Extract Page - ByteScout

ByteScout PDF Extractor SDK – C# – Find Keyword And Extract Page

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Extractor SDK – C# – Find Keyword And Extract Page

ByteScout PDF Extractor SDK – C# – Find Keyword And Extract Page

Program.cs

// This example page extraction by found keyword.

using System;
using Bytescout.PDFExtractor;

namespace SplittingExample
{
class Program
{
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(); } } } [/csharp]


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next