Getting Started with WPF PDF Viewer
22 Jul 20265 minutes to read
This section explains how to create an application that displays a PDF file using the WPF PDF Viewer.
To get started quickly with WPF PDF Viewer, you can check out this video:
Prerequisites
Create a new WPF App in Visual Studio
You can create a WPF Application using Visual Studio via Microsoft Templates or the Syncfusion® WPF.
Assemblies Deployment
To add a WPF PDF Viewer component to your application by installing it via NuGet packages (Recommended) or by manually adding the required assemblies to the project.
Install Syncfusion® WPF PDF Viewer NuGet packages
To add WPF PDF Viewer component in the application, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search and install:
To ensure the control is styled correctly, install the theme package:
• Syncfusion.Themes.Windows11Light.WPF
Rather than referencing the assemblies, you can utilize the PdfViewer NuGet Packages. For more information on how to install the NuGet package in a WPF application, please follow the provided link. How to install nuget packages in a WPF application
Add Syncfusion® WPF PDF Viewer Assemblies
The following table lists the assemblies required to be added in the project when the WPF PDF Viewer control is used in your application.
| Assembly | Description |
|---|---|
| Syncfusion.Compression.Base.dll | This library handles various compression and decompression operations that are used in the PDF file internally. |
| Syncfusion.Pdf.Base.dll | This library contains the PDF reader and creator that supports the PDF Viewer. |
| Syncfusion.PdfToImageConverter.Base.dll | This library is responsible for Pdfium integration and image generation, enhancing the capabilities of the PDF Viewer. |
| Syncfusion.PdfViewer.WPF.dll | This component contains the rendering area and other related UI elements. |
| Syncfusion.Shared.WPF.dll | This component contains various UI controls (ColorPickerPalette and Numeric UpDown) that are used in the PDF Viewer. |
Below are the additional DLLs required for applying themes and skinning to the WPF PDF Viewer control:
| Assembly | Description |
|---|---|
| Syncfusion.Themes.Windows11Light.WPF.dll | Contains the Windows 11 Light theme style for Syncfusion WPF controls. |
| Syncfusion.SfSkinManager.WPF.dll | Contains the SfSkinManager which helps to apply different themes to Syncfusion WPF controls. |
NOTE
You need to add these references to your project to use the skinning and theming capabilities of the PDF Viewer.
NOTE
- Starting with version 23.1.x, Syncfusion PdfToImageConverter is necessary for PDF Viewer applications.
- Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Please refer to this link to know about registering Syncfusion® license key in your WPF application to use our components.
Add WPF PDF Viewer component
WPF PDF Viewer control can be added to an application either through the designer (XAML) or programmatically using code.
- Open the Visual Studio toolbox.
-
Navigate to Syncfusion® WPF Toolbox tab and drag the
PdfViewerControltoolbox item to the Designer window. The required references are automatically added to the current application.
PDF Viewer control in toolbox
3.Use the PdfViewerControl in XAML by including the Syncfusion namespace.
<Window x:Class="Namespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF">
<Grid x:Name="HomeGrid">
<syncfusion:PdfViewerControl x:Name="pdfViewer"></syncfusion:PdfViewerControl>
</Grid>
</Window>N> Declare a name for the PDF Viewer component as shown above for reference.
4.Add the SfSkinManager namespace to style the control correctly, and apply the desired theme.
<Window x:Class="Namespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusionskin="clr-namespace:Syncfusion.SfSkinManager;assembly=Syncfusion.SfSkinManager.WPF"
syncfusionskin:SfSkinManager.Theme="{syncfusionskin:SkinManagerExtension ThemeName=Windows11Light}">
</Window>To add the control manually from code, follow these steps:
- Add the required assemblies as a reference to the project.
- Add the following Syncfusion®; namespace in MainWindow.xaml.cs.
using Syncfusion.Windows.PdfViewer;3.Create a PdfViewerControl instance and add it to the main window.
using Syncfusion.Windows.PdfViewer;
using System.Windows;
namespace PdfViewerDemo
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class MainWindow : Window
{
# region Constructor
public MainWindow()
{
InitializeComponent();
PdfViewerControl pdfViewer = new PdfViewerControl();
HomeGrid.Children.Add(pdfViewer);
}
#endregion
}
}4.The following example code demonstrate how to apply the FluentDark theme to PDF Viewer control in MainWindow.xaml.cs using SfSkinManager.
using Syncfusion.Windows.PdfViewer;
using Syncfusion.SfSkinManager;
public MainWindow()
{
InitializeComponent();
//Initialize PDF Viewer.
PdfViewerControl pdfViewer = new PdfViewerControl();
HomeGrid.Children.Add(pdfViewer);
//Apply the theme to PDFViewer.
SfSkinManager.ApplyThemeAsDefaultStyle = true;
SfSkinManager.SetTheme(pdfViewer, new Theme() { ThemeName = "FluentDark" });
pdfViewer.Load(@"../../PDF_Succinctly.pdf");
}Public Sub New()
InitializeComponent()
'Initialize PDF Viewer.
Dim pdfViewer As PdfViewerControl = New PdfViewerControl()
HomeGrid.Children.Add(pdfViewer)
'Apply the theme to PDFViewer.
SfSkinManager.ApplyThemeAsDefaultStyle = True
SfSkinManager.SetTheme(pdfViewer, New Theme() With {
.ThemeName = "FluentDark"
})
pdfViewer.Load("../../PDF_Succinctly.pdf")
End SubNOTE
View Sample in GitHub.. Looking for the full WPF PDF Viewer component overview, features, pricing, and documentation? Visit the WPF PDF Viewer page.