Articles in this section
Category / Section

How to create PDF Viewer control in C# WPF?

2 mins read

The WPF PDF viewer control supports viewing, reviewing, and printing PDF files in WPF applications. The thumbnail, bookmark, hyperlink, and table of contents support provides easy navigation within and outside the PDF files. The form-filling support provides a platform to fill, flatten, save, and print PDF files with AcroForm. The PDF files can be reviewed with the abundant available annotation tools.

Steps to create a PDF Viewer control in C# WPF application

Step 1: Create a new C# WPF application project.

Step 2: Install the Syncfusion.PdfViewer.WPF NuGet package as a reference to your .NET Framework application.

Install the Syncfusion.PdfViewer.WPF NuGet package as a reference to your .NET framework application.

Step 3: Add the following Syncfusion namespace in MainWindow.xaml to make use of the PdfViewerControl.

XAML

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CreatePdfViewerControl"
        mc:Ignorable="d"
        xmlns:Syncfusion="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF" 
        Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">

Step 4: Use the following code to initialize the PdfViewerControl from XAML.

XAML

<syncfusion:PdfViewerControl x:Name="PdfViewerControl"/>

Step 5: Use the Load API to view the PDF document using PdfViewerControl in MainWindow.xaml.cs file.

C#

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Loads the document in PdfViewerControl
            PdfViewerControl.Load(@"..\..\Data\Barcode.pdf");
        }

Please find the sample from this GitHub location. Execution of PdfViewer Control sample will look alike as follows.

A screenshot of PDF viewer control.

UI customization

You can design and use your own UI for interacting with PDF files using the PdfDocumentView control. This control is exclusive for customization purpose and it supports only viewing the PDF files without having any other built-in UIs. We exposed equivalent APIs for all the functionalities, and you can bind it to your custom UI to make use of all the features. Refer to our API reference for more details.

Toolbar customization

You can design and use your own toolbar by hiding the built-in toolbar from the PdfViewerControl. Refer to this documentation for more details about toggling the visibility of the toolbar and also check out our custom toolbar example in GitHub location, where we have used ribbon control instead of built-in toolbar for PdfViewerControl. Execution of custom toolbar sample will look alike as follows.

A screenshot of a custom toolbar

Appearance customization

As it inherits from System.Windows.Controls.Control, you can change the appearance of the control to fit the look and feel of your application. You can customize the appearance either by creating your own control template or by choosing any of the Syncfusion supported built-in themes that are available in the Syncfusion.Shared.WPF assembly. Check out our visual styles example for the built-in themes supported by PdfViewer control in GitHub location. Execution of visual styles sample with theme “Office 2010 Blue” will look alike as follows.

A screenshot of visual styles sample.

Conclusion

I hope you enjoyed learning about how to create PDF Viewer control in C# WPF.

You can refer to our WPF PDF Viewer page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. 

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!




Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied