[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 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.

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 18.1\Components\Data\Demo.pdf

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.

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.

Important

If the PdfViewerControl.DetachStreamOnLoadComplete property is set to false (default mode) the PDF Viewer locks a file until it is opened in the PDF Viewer. If you want the PDF Viewer does not lock the file, set the PdfViewerControl.DetachStreamOnLoadComplete property to true.

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.

Important

If the PdfViewerControl.DetachStreamOnLoadComplete property is set to false (default mode), the input stream should not be closed until a document is opened.

If you want to close the stream when a document is opened, set the PdfViewerControl.DetachStreamOnLoadComplete property to true before specifying the document source.

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

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