Lesson 1 - Create a PDF Viewer
- 4 minutes to read
This tutorial illustrates how to embed a PDF Viewer in a Windows Forms application, to open, preview, navigate and print PDF documents without the need to install third-party software on the machine.
The tutorial consists of the following sections.
- Create a PDF Viewer Application
- Create and Customize the Toolbar
- Change the Application’s Appearance
- Load and Preview a PDF File
Create a PDF Viewer Application
- Run Microsoft® Visual Studio® 2012, 2013, 2015 or 2017.
Start a new project (by pressing CTRL+SHIFT+N), and create a new Windows Forms Application.
Open the Visual Studio designer and press CTRL+ALT+X to run the Toolbox. Expand the DX.18.2: Common Controls category, and drop the PdfViewer control onto the main form of the application.
Click the PDF Viewer’s smart tag to invoke its actions list. In the actions list, click the Dock in parent container link. This allows the PDF Viewer to occupy all of the available space on the form.
After docking the PDF Viewer, it will appear as follows.
Create and Customize the Toolbar
To add a toolbar to the PDF Viewer, click the control’s smart tag, and in the invoked actions list, select one of the following.
Create Ribbon
Then, click the Create All Bars link in the actions list.
This creates a ribbon illustrated in the following image.
Note
To create only PDF Viewer bar, Interactive Form bar or Comment bar, choose the corresponding link in the actions list.
You can fully customize the ribbon afterwards, as well as select a different look and feel for it, via the smart tag of the toolbar.
Create Bars
Instead of creating a ribbon, you can implement a bar interface. You can upgrade it to the ribbon interface at any time (e.g., when converting the entire application).
Change the Application’s Appearance
Change the application’s skin
At design time
In code
Invoke the DevExpress Project Settings page and select a desired skin in the Skin Options group.
Call the UserLookAndFeel.Default static object’s UserLookAndFeel.SetSkinStyle method:
Change the PDF Viewer’s skin
Use the LookAndFeel property to access an object specifying the control’s look and feel settings.
Use bitmap or vector icons
The PDF Viewer uses vector icons by default, which ensures that the application is rendered correctly on high-DPI devices.
Set the static WindowsFormsSettings.AllowDefaultSvgImages property to DefaultBoolean.False at the application’s startup to make your application use bitmap icons in the GUI.
static void Main() { DevExpress.XtraEditors.WindowsFormsSettings.AllowDefaultSvgImages = DevExpress.Utils.DefaultBoolean.False; // ... }
The following images illustrate the standard PDF Viewer’s ribbon UI with default vector and bitmap icons:
SVG Icons Bitmap Icons
Load and Preview a PDF File
To load a document into the PDF Viewer, click the control’s smart tag and select Load PDF file… in the actions list that is invoked.
To learn more about several ways of loading a document in the PDF Viewer, refer to the Lesson 2 - Load a Document tutorial.
Note
The PDF Viewer shows bookmarks within its navigation pane for a document that contains them. So you can quickly locate and link to points of interest within a document. For more information, see the Bookmarks topic.
You can also see file attachments and thumbnails in theAttachments and Page Thumbnails panels on the navigation pane. For more information, see File Attachment, and Thumbnails topics.
Run the application and explore the PDF Viewer functionality.