Use the ExtractText property of the ViewInfoOptions class to get the text contained in a source document and its coordinates. Then you can use this data to add a selectable text over the image or to implement a text search in image-based rendering.
The following code snippet shows how to retrieve and print out text (lines/words/characters) on each document page with coordinates:
usingSystem;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;usingGroupDocs.Viewer.Results;// ...using(Viewerviewer=newViewer("sample.docx")){// Get the file information and extract it text.boolextractText=true;ViewInfoOptionsviewInfoOptions=ViewInfoOptions.ForPngView(extractText);ViewInfoviewInfo=viewer.GetViewInfo(viewInfoOptions);// Display the file information and text.foreach(PagepageinviewInfo.Pages){Console.WriteLine($"Page: {page.Number}");Console.WriteLine("Text lines/words/characters:");foreach(Linelineinpage.Lines){Console.WriteLine(line);foreach(Wordwordinline.Words){Console.WriteLine($"\t{word}");foreach(Charactercharacterinword.Characters){Console.WriteLine($"\t\t{character}");}}}}}
ImportsSystemImportsGroupDocs.ViewerImportsGroupDocs.Viewer.OptionsImportsGroupDocs.Viewer.Results' ...
ModuleProgramSubMain(argsAsString())UsingviewerAsViewer=NewViewer("sample.docx")' Get the file information and extract it text.
DimextractTextAsBoolean=TrueDimviewInfoOptionsAsViewInfoOptions=ViewInfoOptions.ForPngView(extractText)DimviewInfoAsViewInfo=viewer.GetViewInfo(viewInfoOptions)' Display the file information and text.
ForEachpageAsPageInviewInfo.PagesConsole.WriteLine($"Page: {page.Number}")Console.WriteLine("Text lines/words/characters:")ForEachlineAsLineInpage.LinesConsole.WriteLine(line)ForEachwordAsWordInline.WordsConsole.WriteLine($" {word}")ForEachcharacterAsCharacterInword.CharactersConsole.WriteLine($" {character}")NextNextNextNextEndUsingEndSubEndModule
The following image shows a sample console output:
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.