Image Viewer - Get text coordinates

GroupDocs.Viewer provides the feature of getting text coordinates. This feature is useful if you want to add selectable text over the image or implement a text search in image-based rendering. 

The ExtractText property of ViewInfoOptions classenables you to get the text contained in a source document with coordinates.

Following code sample shows how to retrieve and print out text (lines / words / characters) of each document page with coordinates.

 			using (Viewer viewer = new Viewer("sample.docx"))
            {
                ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForPngView(true);
                ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);
 
                foreach(Page page in viewInfo.Pages)
                {
                    Console.WriteLine($"Page: {page.Number}");
                    Console.WriteLine("Text lines/words/characters:");
                                        
                    foreach (Line line in page.Lines)
                    {
                        Console.WriteLine(line);
                        foreach (Word word in line.Words)
                        {
                            Console.WriteLine($"\t{word}");
                            foreach (Character character in word.Characters)
                            {
                                Console.WriteLine($"\t\t{character}");
                            }
                        }
                    }
                }
            }

More resources

Advanced Usage Topics

To learn more about document viewing features, please refer to the advanced usage section.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.