Get text coordinates

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:

using System;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;
// ...

using (Viewer viewer = new Viewer("sample.docx"))
    // Get the file information and extract it text.
    bool extractText = true;
    ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForPngView(extractText);
    ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);

    // Display the file information and text.
    foreach (Page page in viewInfo.Pages)
        Console.WriteLine($"Page: {page.Number}");
        Console.WriteLine("Text lines/words/characters:");

        foreach (Line line in page.Lines)
            foreach (Word word in line.Words)
                foreach (Character character in word.Characters)
Imports System
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.docx")
            ' Get the file information and extract it text.
            Dim extractText As Boolean = True
            Dim viewInfoOptions As ViewInfoOptions = ViewInfoOptions.ForPngView(extractText)
            Dim viewInfo As ViewInfo = viewer.GetViewInfo(viewInfoOptions)
            ' Display the file information and text.
            For Each page As Page In viewInfo.Pages
                Console.WriteLine($"Page: {page.Number}")
                Console.WriteLine("Text lines/words/characters:")
                For Each line As Line In page.Lines
                    For Each word As Word In line.Words
                        Console.WriteLine($"	{word}")
                        For Each character As Character In word.Characters
                            Console.WriteLine($"		{character}")
        End Using
    End Sub
End Module

The following image shows a sample console output: