How can I help you?
Getting Started with WPF Pdf Viewer
22 Jun 20267 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 on 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 pdfviewer component to your application by installing it via NuGet packages(Recommended) or by manually adding the required assemblies to the project.
Install Syncfusion® WPF PdfViewer NuGet packages
To add WPF pdfViewer 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 pdfviewer Assemblies
Below table describes, list of assemblies required to be added in project when the WPF pdfviewer 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 PdfViewer 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 PdfViewer.
NOTE
- Starting with version 23.1.x, Syncfusion PdfToImageConverter is necessary for PdfViewer 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 PdfViewer component
WPF PdfViewer 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, it automatically adds the required references to the current application.
PDF viewer control in toolbox - PdfViewer can be added to the application by dragging
PdfViewerControlto the Designer area.
<Window
<Grid x:Name="HomeGrid">
<syncfusion:PdfViewerControl x:Name="pdfViewer"></syncfusion:PdfViewerControl>
</Grid>
</Window>NOTE
Declare a name for the PdfViewer component as shown above for reference.
- Add the theme and the SfSkinManager namespace to style the control correctly. Then, include the SfSkinManager namespace in the XAML code 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 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;- 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
}
}- The following example code demonstrate how to apply the FluentDark theme to PDF Viewer control in MainWindow.xaml.cs .
public MainWindow()
{
InitializeComponent();
//Initialize PDF Viewer.
PdfViewerControl pdfViewer1 = 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