Export Word to ImageSource in WPF

Following sample shows how to convert document page to ImageSource instance and attach it to WPF's Image control.

Screenshot

Export to ImageSource / Image Control Screenshot

See the full code below.

<Window x:Class="ConvertToImageSourceCs.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Export to ImageSource Sample" 
        SizeToContent="WidthAndHeight">

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

</Window>
1using System.Windows;
2using System.Windows.Controls;
3using GemBox.Document;
4
5namespace ConvertToImageSourceCs
6{
7    public partial class MainWindow : Window
8    {
9        public MainWindow()
10        {
11            InitializeComponent();
12
13            SetImageSource(this.ImageControl);
14        }
15
16        private static void SetImageSource(Image image)
17        {
18            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
19
20            DocumentModel document = new DocumentModel();
21
22            var section = new GemBox.Document.Section(document);
23            document.Sections.Add(section);
24
25            var paragraph = new GemBox.Document.Paragraph(document);
26            section.Blocks.Add(paragraph);
27
28            var run = new GemBox.Document.Run(document, "Hello World!");
29            paragraph.Inlines.Add(run);
30
31            image.Source = document.ConvertToImageSource(SaveOptions.ImageDefault);
32        }
33    }
34}
1Imports System.Windows
2Imports System.Windows.Controls
3Imports GemBox.Document
4
5Class MainWindow
6
7    Public Sub New()
8        InitializeComponent()
9
10        SetDocumentViewer(Me.ImageControl)
11    End Sub
12
13    Private Shared Sub SetDocumentViewer(image As Image)
14
15        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
16
17        Dim document = New DocumentModel()
18
19        Dim section = New GemBox.Document.Section(document)
20        document.Sections.Add(section)
21
22        Dim paragraph = New GemBox.Document.Paragraph(document)
23        section.Blocks.Add(paragraph)
24
25        Dim run = New GemBox.Document.Run(document, "Hello World!")
26        paragraph.Inlines.Add(run)
27
28        image.Source = document.ConvertToImageSource(SaveOptions.ImageDefault)
29
30    End Sub
31
32End Class

Check next sample or find out more about GemBox.Document and GemBox Software.