GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

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.

Screenshot
Get Content Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.Text;
using System.Linq;
using GemBox.Document;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("Reading.docx");

        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 System.Linq
Imports GemBox.Document

Module Samples

    Sub Main()

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

        Dim document As DocumentModel = DocumentModel.Load("Reading.docx")

        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 sample.