Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   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]Interactive Forms
   [Expand]Navigation
   [Expand]Interactivity
   [Expand]Examples
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [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]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Lesson 2 - Loading a Document

This is the second tutorial in the Getting Started series for the PDF Viewer control. It describes several ways of loading a document in the PDF Viewer.

The tutorial consists of the following section.

Expanded Prerequisites

Before loading a document, you need to add a PDF Viewer to your WPF application. To learn how to do this, refer to How to: Add a PDF Viewer at Design Time and How to: Add a PDF Viewer via Code tutorials.

When no document is loaded, the PDF Viewer shows the Start Screen, if the PdfViewerControl.ShowStartScreen property is set to true. On this screen, an end-user can open one of the recently opened documents or invoke the Open dialog box.

To disable the Start Screen, set the PdfViewerControl.ShowStartScreen property to false.

The PdfViewerControl.NumberOfRecentFiles property limits the number of recently opened files that are displayed in the Start Screen. The PdfViewerControl.ShowOpenFileOnStartScreen property allows you to hide the Open button.

Note

In this tutorial Demo.pdf is used. This PDF document is shipped with the WPF PDF Viewer demo. Copy the file to the subdirectory of your project. By default, this file is located in the following folder.

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

Expanded Load from a File

Use one of the following approaches.

  • Call the PdfViewerControl.OpenDocument method with a specified file path.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T271077.

  • Assign a path to the file using the DocumentViewerControl.DocumentSource property.

  • or...
  • Use an Open dialog box at runtime.
    • Run the application.

    • Click the Open button or press CTRL+O to show the Open dialog box.

    • Locate the document to be opened and click Open.

Expanded Load from the Stream

The PDF Viewer can load a document from a stream obtained from various sources, for example, from an application resource, as shown below.

To load a document from a stream, assign the stream object to the DocumentViewerControl.DocumentSource property.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T263193.

Note that when you load a document, the input stream should not be closed before the control finishes using a document (PdfViewerControl.DetachStreamOnLoadComplete is set to false by default). This allows the PDF Viewer to render a large PDF quickly.

If you want to close the stream after a document is loaded into the PDF Viewer, set the PdfViewerControl.DetachStreamOnLoadComplete property to true. However, in this case the high rendering performance is not guaranteed.

Expanded Load from a Uri

Create a Uri object with the specified base Uri and file path, and assign this object to the DocumentViewerControl.DocumentSource property.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T263203.

Expanded See Also

How would you rate this topic?​​​​​​​