The following example shows how to extract a text from a document:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract a text into the readerusing(TextReaderreader=parser.GetText()){// Print a text from the document// If text extraction isn't supported, a reader is nullConsole.WriteLine(reader==null?"Text extraction isn't supported":reader.ReadToEnd());}}
The following example shows how to extract a raw text from a document:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract a raw text into the readerusing(TextReaderreader=parser.GetText(newTextOptions(true))){// Print a text from the document// If text extraction isn't supported, a reader is nullConsole.WriteLine(reader==null?"Text extraction isn't supported":reader.ReadToEnd());}}
The following example shows how to extract a text from the document page:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Check if the document supports text extractionif(!parser.Features.Text){Console.WriteLine("Document isn't supports text extraction.");return;}// Get the document infoIDocumentInfodocumentInfo=parser.GetDocumentInfo();// Check if the document has pagesif(documentInfo.PageCount==0){Console.WriteLine("Document hasn't pages.");return;}// Iterate over pagesfor(intp=0;p<documentInfo.PageCount;p++){// Print a page number Console.WriteLine(string.Format("Page {0}/{1}",p+1,documentInfo.PageCount));// Extract a text into the readerusing(TextReaderreader=parser.GetText(p)){// Print a text from the document// We ignore null-checking as we have checked text extraction feature support earlierConsole.WriteLine(reader.ReadToEnd());}}}
The following example shows how to extract a raw text from the document page:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Check if the document supports text extractionif(!parser.Features.Text){Console.WriteLine("Document isn't supports text extraction.");return;}// Get the document infoDocumentInfodocumentInfo=parser.GetDocumentInfo()asDocumentInfo;// Check if the document has pagesif(documentInfo==null||documentInfo.RawPageCount==0){Console.WriteLine("Document hasn't pages.");return;}// Iterate over pagesfor(intp=0;p<documentInfo.RawPageCount;p++){// Print a page number Console.WriteLine(string.Format("Page {0}/{1}",p+1,documentInfo.RawPageCount));// Extract a text into the readerusing(TextReaderreader=parser.GetText(p,newTextOptions(true))){// Print a text from the document// We ignore null-checking as we have checked text extraction feature support earlierConsole.WriteLine(reader.ReadToEnd());}}}