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 (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)
        {
            Console.WriteLine(line);
            foreach (Word word in line.Words)
            {
                Console.WriteLine($"\t{word}");
                foreach (Character character in word.Characters)
                {
                    Console.WriteLine($"\t\t{character}");
                }
            }
        }
    }
}

The following image shows a sample console output: