Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[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]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
   [Expand]Interactive Forms
   [Expand]Navigation
   [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]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 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:

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

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

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.

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.

Note that when you load a document, the input stream should not be closed before the control finishes using a document (PdfViewer.DetachStreamAfterLoadComplete 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 PdfViewer.DetachStreamAfterLoadComplete property to true. However, in this case, high rendering performance is not guaranteed.

Expanded See Also

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