Get Content

Content of a document is represented with ContentRange class which is exposed on following members:

Following example demonstrates how to retrieve plain text representation of document elements by using ContentRange.ToString() method on their content.

Get Content Screenshot
Upload your file (Drag file here)
using System;
using System.Text;
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        var sb = new StringBuilder();

        // Get content from each paragraph
        foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
        {
            sb.AppendFormat("Paragraph: {0}", paragraph.Content.ToString());
            sb.AppendLine();
        }

        // Get content from each bold run
        foreach (Run run in document.GetChildElements(true, ElementType.Run))
        {
            if (run.CharacterFormat.Bold)
            {
                sb.AppendFormat("Bold run: {0}", run.Content.ToString());
                sb.AppendLine();
            }
        }

        Console.WriteLine(sb.ToString());
    }
}
Imports System
Imports System.Text
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        Dim sb = New StringBuilder()

        ' Get content from each paragraph
        For Each paragraph As Paragraph In document.GetChildElements(True, ElementType.Paragraph)
            sb.AppendFormat("Paragraph: {0}", paragraph.Content.ToString())
            sb.AppendLine()
        Next

        ' Get content from each bold run
        For Each run As Run In document.GetChildElements(True, ElementType.Run)
            If (run.CharacterFormat.Bold) Then
                sb.AppendFormat("Bold run: {0}", run.Content.ToString())
                sb.AppendLine()
            End If
        Next

        Console.WriteLine(sb.ToString())

    End Sub

End Module

Check next example or download examples from GitHub.