Convert Word document to Image in WPF

6 Jul 20233 minutes to read

Syncfusion DocIO is a .NET Word library used to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can convert a Word document to image in WPF.

Steps to convert Word document to Image in WPF

Step 1: Create a new WPF application project.

Create WPF application in Visual Studio

Step 2: Install the Syncfusion.DocIO.Wpf NuGet package as a reference to your WPF application from NuGet.org.

Install Syncfusion.DocIO.Wpf NuGet package

NOTE

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Please refer to this link to know about registering Syncfusion license key in your application to use our components.

Step 3: Include the following namespaces in the MainWindow.xaml.cs file.

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

Step 4: Add a new button in MainWindow.xaml to convert Word document to image file as follows.

<Button Click="btnConvert_Click" VerticalAlignment="Center" Height="30" BorderBrush="LightBlue" HorizontalAlignment="Center" Width="150">
    <Button.Background>
        <LinearGradientBrush EndPoint="0.5,-0.04" StartPoint="0.5,1.04">
            <GradientStop Color="#FFD9E9F7" Offset="0"/>
            <GradientStop Color="#FFEFF8FF" Offset="1"/>
        </LinearGradientBrush>
    </Button.Background>
    <StackPanel Orientation="Horizontal" Height="23" Margin="0,0,0,-2.52" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="100" RenderTransformOrigin="0.5,0.5">
        <StackPanel.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="-0.226"/>
                <TranslateTransform/>
            </TransformGroup>
        </StackPanel.RenderTransform>
    <Image Name="image2" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <TextBlock Text="Word to Image" Height="38" Width="187" Margin="0,4,0,3" TextWrapping="WrapWithOverflow" />
</StackPanel>
</Button>

Step 5: Add the following code in btnConvert_Click to convert Word document to image with simple text.

using (WordDocument document = new WordDocument("Input.docx", FormatType.Docx))
{
    //Convert the first page of the Word document into an image.
    System.Drawing.Image image = document.RenderAsImages(0, ImageType.Bitmap);
    //Save the image as jpeg.
    image.Save("WordToImage.Jpeg", ImageFormat.Jpeg);
}

You can download a complete working sample from GitHub.

By executing the program, you will get the image as follows.

Word to Image in WPF

Click here to explore the rich set of Syncfusion Word library (DocIO) features.

An online sample link to convert Word document to image in ASP.NET Core.