Export Word to ImageSource in WPF

Besides converting a document to a different file format, GemBox.Document also supports converting a document's pages to ImageSource objects with the DocumentModel.ConvertToImageSource method.

If you require more than displaying a file's content, for instance if you want to be able to modify it with some GUI control, take a look at this Word Editor in WPF example.

The following example demonstrates how you can convert a page from a Word file to an image and attach it to WPF's Image control.

Screenshot of Word file exported to WPF's Image control
Converted page from Word file to ImageSource and attached to WPF's Image control
<Window x:Class="ConvertToImageSource.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Export to ImageSource / Image Control"
        SizeToContent="WidthAndHeight">

    <Border Margin="10" BorderBrush="Black" BorderThickness="1">
        <Image x:Name="ImageControl"/>
    </Border>

</Window>
using System.Windows;
using GemBox.Document;

namespace ConvertToImageSource
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();

            // If using Professional version, put your serial key below.
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
            
            this.SetImageControl("%#Reading.docx%", 0);
        }

        private void SetImageControl(string path, int pageIndex)
        {
            var document = DocumentModel.Load(path);

            var imageOptions = new ImageSaveOptions();
            imageOptions.PageNumber = pageIndex;

            var imageSource = document.ConvertToImageSource(imageOptions);
            this.ImageControl.Source = imageSource;
        }
    }
}
Imports System.Windows
Imports GemBox.Document

Namespace ConvertToImageSource
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()

            Me.InitializeComponent()

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

            Me.SetImageControl("%#Reading.docx%", 0)

        End Sub

        Private Sub SetImageControl(path As String, pageIndex As Integer)

            Dim document = DocumentModel.Load(path)

            Dim imageOptions As New ImageSaveOptions()
            imageOptions.PageNumber = pageIndex

            Dim imageSource = document.ConvertToImageSource(imageOptions)
            Me.ImageControl.Source = imageSource

        End Sub

    End Class
End Namespace

Check next example or download examples from GitHub.