The following example shows how to extract a document text as HTML text:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract a formatted text into the readerusing(TextReaderreader=parser.GetFormattedText(newFormattedTextOptions(FormattedTextMode.Html))){// Print a formatted text from the document// If formatted text extraction isn't supported, a reader is nullConsole.WriteLine(reader==null?"Formatted text extraction isn't suppported":reader.ReadToEnd());}}
The following example shows how to extract a document page text as Markdown text:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Check if the document supports formatted text extractionif(!parser.Features.FormattedText){Console.WriteLine("Document isn't supports formatted 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 formatted text into the readerusing(TextReaderreader=parser.GetFormattedText(p,newFormattedTextOptions(FormattedTextMode.Markdown))){// Print a formatted text from the document// We ignore null-checking as we have checked formatted text extraction feature support earlierConsole.WriteLine(reader.ReadToEnd());}}}