Export PDF file to ImageSource in WPF

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

PDF page exported to ImageSource with GemBox.Pdf
Screenshot of PDF page exported to ImageSource with GemBox.Pdf
<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Export to ImageSource Example" 
        SizeToContent="WidthAndHeight">

    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Header="_Open" Click="MenuItem_Click" />
            </MenuItem>
        </Menu>
        <Border Margin="10" BorderBrush="Black" BorderThickness="1">
            <Image x:Name="ImageControl"/>
        </Border>
    </DockPanel>

</Window>
using System.Windows;
using GemBox.Pdf;
using Microsoft.Win32;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
    }

    private void MenuItem_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog fileDialog = new OpenFileDialog();
        fileDialog.Filter = "PDF files (*.pdf)|*.pdf";

        if (fileDialog.ShowDialog() == true)
        {
            using (var document = PdfDocument.Load(fileDialog.FileName))
            {
                this.ImageControl.Source = document.ConvertToImageSource(SaveOptions.Image);
            }
        }
    }
}
Imports GemBox.Pdf
Imports Microsoft.Win32

Class MainWindow

    Public Sub New()

        InitializeComponent()

        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
    End Sub

    Private Sub MenuItem_Click(sender As Object, e As RoutedEventArgs)

        Dim fileDialog = New OpenFileDialog()
        fileDialog.Filter = "PDF files (*.pdf)|*.pdf"

        If (fileDialog.ShowDialog() = True) Then
            Using document = PdfDocument.Load(fileDialog.FileName)
                Me.ImageControl.Source = document.ConvertToImageSource(SaveOptions.Image)
            End Using
        End If

    End Sub
End Class

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Pdf yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.