Click or drag to resize

Getting Started with ExpertPdf PDF Viewer for Windows Forms and WPF

ExpertPdf PDF Viewer for Windows Forms and WPF displays PDF documents in your desktop applications. The users get a complete PDF reader: page thumbnails, the document outline (bookmarks) and attachments panels, text search and selection, zoom and fit modes, page layouts, printing and download. Your code opens the documents, drives the viewer and follows what the user does.

The viewer is delivered as one assembly, PdfViewerWinNet.dll, with two controls:

Both controls have the same members.

Features
  • Open documents from a file, a stream or a byte array - for example a document you have just created with ExpertPdf HTML to PDF Converter - without saving it first.

  • Open password protected documents, with or without asking the user for the password: your application can give the password when the viewer needs it, and is told when a password is wrong.

  • Navigate: first, previous, next and last page, a page number, a named destination, back and forward through the views already visited.

  • Find text from code: the matches are highlighted, and an event gives their number and the selected match.

  • Change the view: zoom percentage, fit the page, the page width or the page height, single page, continuous or two-page layouts, the navigation panel (thumbnails, bookmarks, attachments), the toolbar and the scrollbars.

  • Light or dark theme (or as set in Windows), and single toolbar buttons shown or hidden: open, navigation panel, find, page navigation, zoom, print, download, presentation mode, document properties.

  • Print with the print dialog, or directly on a printer without any dialog - the whole document or a range of pages.

  • Protect the displayed document: passwords, and the permissions to print and to copy the content.

  • Set how a document opens with viewer preferences: the page layout and the panel shown next to it.

  • Follow the viewer with events: the document has loaded, the user moved to another page, a document could not be opened.

What's new
Requirements
  • .NET Framework 4.6.2 or later, or .NET 8 or later, on Windows.

  • The Microsoft Edge WebView2 Runtime. It is part of Windows 10 and Windows 11. On Windows Server and on older systems install the Evergreen WebView2 Runtime from https://go.microsoft.com/fwlink/p/?LinkId=2124703, or distribute a fixed version of the runtime with your application (see Deployment).

  • The Microsoft.Web.WebView2 NuGet package in your project. The ExpertPdf.PdfViewer.WinForms package adds it for you.

Adobe Reader is not needed.

Installation using the NuGet package

The easiest way to install the viewer is the ExpertPdf.PdfViewer.WinForms package (https://www.nuget.org/packages/ExpertPdf.PdfViewer.WinForms/). It works for Windows Forms and WPF projects, for .NET Framework 4.6.2+ and .NET 8+. In Visual Studio open the NuGet Package Manager and install the package, or run:

dotnet add package ExpertPdf.PdfViewer.WinForms
Installation using the downloaded assemblies

The download contains:

  • Bin\PdfViewerWinNet.dll - the viewer for .NET Framework 4.6.2 and later

  • Bin\.NET_8.0\PdfViewerWinNet.dll - the viewer for .NET 8 and later

  • Samples and Samples_NET_10 - Windows Forms (C#, VB.NET) and WPF (C#) samples

Add a reference to the PdfViewerWinNet.dll for your framework and install the Microsoft.Web.WebView2 NuGet package in your project.

Getting started with Windows Forms

After you reference the viewer, the PdfViewer control appears in the Visual Studio Toolbox (if it does not, right click the Toolbox, select Choose Items and browse to PdfViewerWinNet.dll). Drag it on a form, or create it in code:

using PdfViewer4WinNet;

public partial class MainForm : Form
{
    private readonly PdfViewer pdfViewer = new PdfViewer();

    public MainForm()
    {
        InitializeComponent();

        // without a license key the viewer shows an evaluation notice
        pdfViewer.LicenseKey = "your license key";
        pdfViewer.Dock = DockStyle.Fill;
        Controls.Add(pdfViewer);

        // the document is displayed: the page count and the current page are known
        pdfViewer.DocumentLoaded += (s, e) => Text = pdfViewer.PageCount + " pages";
        pdfViewer.LoadError += (s, e) => MessageBox.Show(e.Message);

        pdfViewer.LoadFile(@"C:\Documents\report.pdf");
    }
}
Getting started with WPF

Declare the namespace of the WPF control in XAML and add the control to a window:

XML
<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:epdf="clr-namespace:PdfViewer4WinNet.Wpf;assembly=PdfViewerWinNet"
        Title="PDF reader" Width="1000" Height="750">
    <epdf:PdfViewer x:Name="pdfViewer" LicenseKey="your license key"
                    Source="C:\Documents\report.pdf"
                    DocumentLoaded="pdfViewer_DocumentLoaded" />
</Window>

The Source property loads a file and can be bound to your view model. All the other members - LoadFile, LoadBytes, navigation, view, printing, security - are the same as in the Windows Forms control.

Licensing

A license key is emailed to you when you purchase the product. Set it with the LicenseKey property before you load a document. Without a valid license key the viewer works the same, and shows an evaluation notice.

Next steps
See Also