The following example shows how to extract all text areas from the whole document:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract text areasIEnumerable<PageTextArea>areas=parser.GetTextAreas();// Check if text areas extraction is supportedif(areas==null){Console.WriteLine("Page text areas extraction isn't supported");return;}// Iterate over page text areasforeach(PageTextAreaainareas){// Print a page index, rectangle and text area value:Console.WriteLine(string.Format("Page: {0}, R: {1}, Text: {2}",a.Page.Index,a.Rectangle,a.Text));}}
The following example shows how to extract only text areas with digits from the upper-left courner:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Create the options which are used for text area extractionPageTextAreaOptionsoptions=newPageTextAreaOptions("[0-9]+",newRectangle(newPoint(0,0),newSize(300,100)));// Extract text areas which contain only digits from the upper-left courner of a page:IEnumerable<PageTextArea>areas=parser.GetTextAreas(options);// Check if text areas extraction is supportedif(areas==null){Console.WriteLine("Page text areas extraction isn't supported");return;}// Iterate over page text areasforeach(PageTextAreaainareas){// Print a page index, rectangle and text area value:Console.WriteLine(string.Format("Page: {0}, R: {1}, Text: {2}",a.Page.Index,a.Rectangle,a.Text));}}
To extract text areas from a document page the following method is used:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Check if the document supports text areas extractionif(!parser.Features.TextAreas){Console.WriteLine("Document isn't supports text areas 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(intpageIndex=0;pageIndex<documentInfo.PageCount;pageIndex++){// Print a page number Console.WriteLine(string.Format("Page {0}/{1}",pageIndex+1,documentInfo.PageCount));// Iterate over page text areas// We ignore null-checking as we have checked text areas extraction feature support earlierforeach(PageTextAreaainparser.GetTextAreas(pageIndex)){// Print a rectangle and text area value:Console.WriteLine(string.Format("R: {0}, Text: {1}",a.Rectangle,a.Text));}}}