[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Collapse]PDF Viewer
   [Collapse]Getting Started
     Lesson 1 - Creating a PDF Viewer
     Lesson 2 - Loading a Document
    Coordinate Systems
   [Expand]Navigation
   [Expand]Access and Edit Document Content
   [Expand]Interactivity
    Deployment
   [Expand]Examples
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[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 tutorial in the Getting Started series for the PDF Viewer control. It describes several ways of loading a document in the PDF Viewer and consists of the following sections:

Note

This tutorial uses the Demo.pdf that comes shipped with the WinForms PDF Viewer demo. Copy the file to the subdirectory of your project. This file is located in the following folder by default:

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

Before loading a document, you need to add a PDF Viewer to your WinForms application. Refer to How to: Add a PDF Viewer to the WinForms Application at Design Time and How to: Add a PDF Viewer to the WinForms Application via Code tutorials on how to do this.

Expanded Load from a File

Use one of the following approaches:

  • Call the PdfViewer.LoadDocument 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=E4696.

  • At design time, click the PdfViewer's smart tag to invoke its actions list. In the Actions list, click the Load PDF file... link.

    The Open dialog box appears. In this dialog, locate the document to be opened and click Open.

  • or...
  • Use an Open dialog box at runtime.
    • Click the Open button or press CTRL+O to show the Open dialog box.

    • In the dialog, click Open to load a desired document to the PDF Viewer.

Important

If the PdfViewer.DetachStreamAfterLoadComplete 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 PdfViewer.DetachStreamAfterLoadComplete 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, pass the stream object as a parameter to one of the PdfViewer.LoadDocument overloaded methods.

Show Me

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

Important

If the PdfViewer.DetachStreamAfterLoadComplete 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 PdfViewer.DetachStreamAfterLoadComplete property to true before specifying the document source.

Expanded See Also

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