[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Collapse]PDF Viewer
   [Collapse]Getting Started
     Lesson 1 - Creating a PDF Viewer
     Lesson 2 - Loading a Document
   [Expand]Navigation
   [Expand]Access and Edit Document Content
   [Expand]Interactivity
   [Expand]Examples
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Lesson 1 - Creating a PDF Viewer

This document demonstrates how to create a WPF PDF Viewer that opens, previews, navigates and prints PDF documents, without the need to install third-party software on a machine.

This tutorial consists of the following steps.

Expanded Step 1. Create a New Project and Add a PDF Viewer

In this step, you will perform the common actions that are required when you add a PdfViewerControl to your application.

  • Run Microsoft Visual Studio 2010, 2012, 2013, 2015 or 2017.

  • Create a new WPF Application project.

  • Add a PdfViewerControl component to the project.

    To do this, drag the PdfViewerControl from the DX.18.1: Data & Analytics Toolbox tab and drop it onto the main window.

  • Right-click the PDF Viewer and select Layout | Reset All to fill the entire window.

  • After this action, your XAML appears as follows.

    Note that you can add the PdfViewerControl by overwriting your MainWindow.xaml file with this code without dragging the PdfViewerControl control to the window. However, in this case, you need to manually add references to the following libraries.

    • DevExpress.Data.v18.1.dll
    • DevExpress.Mvvm.v18.1.dll
    • DevExpress.Pdf.v18.1.Core.dll
    • DevExpress.Pdf.v18.1.Drawing.dll
    • DevExpress.Xpf.Core.v18.1.dll
    • DevExpress.Xpf.Docking.v18.1.dll
    • DevExpress.Xpf.DocumentViewer.v18.1.Core.dll
    • DevExpress.Xpf.Grid.v18.1.dll
    • DevExpress.Xpf.PdfViewer.v18.1.dll

    To add references, right-click References in the Solution Explorer and select Add Reference… in the invoked context menu.

    Note

    To collect all assemblies that may be required for your application, use the Assembly Deployment Tool.

    Normally, when adding references to these assemblies, you should choose them from the Global Assembly Cache (GAC). However, if you prefer to copy the references locally, or need to include them later in your product installation, you can find copies of them in the following directory.
    C:\Program Files (x86)\DevExpress 18.1\Components\Bin\Framework\

    Now, you have a PDF Viewer added to our application. Continue and customize the command bar style.

Expanded Step 2. Change the Command Bar Style

To change the default ribbon style:

click the control's smart tag to invoke the Tasks list and select the Bars command bar style, as shown below

or

set the DocumentViewerControl.CommandBarStyle property to CommandBarStyle.Bars.

You can see that the PDF Viewer control displays command buttons.

Note

If you want to hide the PdfViewerControl's toolbar and context menu, set the DocumentViewerControl.CommandBarStyle property to CommandBarStyle.None.

Expanded Step 3. Load a Document

The PdfViewerControl provides different ways to load a PDF document. To learn more, see the Lesson 2 - Loading a Document tutorial.

This lesson describes, in details, how to specify a path to the document at design time using the DocumentViewerControl.DocumentSource property. To do this task:

  • Copy a file (e.g., Demo.pdf) to the Data subdirectory of your project and include this file into your solution.

    Note

    For this lesson, we can use the PDF document shipped with the WPF PDF Viewer demo. By default, this file is located in the following folder.

    C:\Users\Public\Documents\DevExpress Demos 18.1\Components\Data\Demo.pdf

  • Specify a path to the file you wish to load by using the DocumentViewerControl.DocumentSource property. The XAML below shows how this can be done for Demo.pdf.

Expanded Result

Run the application to see the loaded file.

Note

The PDF Viewer can show bookmarks within its navigation pane for a PDF document that supports them. For more information, see the Bookmarks topic.

You can also see file attachments and thumbnails in the Attachments and Page Thumbnails panels on the navigation pane. For more information, see the File Attachment, and Thumbnails topics.

After a PDF document is loaded, you can navigate, zoom and print the document using the corresponding bar commands.

Expanded See Also

Is this topic helpful?​​​​​​​