Skip to main content
A newer version of this page is available. .

Lesson 1 - Creating a PDF Viewer

  • 3 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 an Application and Add a PDF Viewer

  1. Run Microsoft® Visual Studio® 2010, 2012, 2013, 2015 or 2017.
  2. Start a new project (by pressing CTRL+SHIFT+N), and create a new Windows Forms Application.

    win-create-new-application

  3. Open the Visual Studio designer and press CTRL+ALT+X to run the Toolbox. Expand the DX.17.2: Common Controls category, and drop the PdfViewer control onto the main form of the application.

    toolbox-common-controls-pdf-viewer

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

    DockInContainer

  5. After docking the PDF Viewer, it will appear as follows.

    Form

Create and Customize a PDF Viewer 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

    smart-tag-create-ribbon

    Then, click the Create All Bars link in the actions list.

    CreateAllBars

    This creates a ribbon illustrated in the following image.

    RibbonPage

    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.

    smart-tag-ribbon-action-list-view-options

  • 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).

    create-bars-bar-manager-convert-to-ribbon

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.

smart-tag-ribbon-load-pdf-file

To learn more about several ways of loading a document in the PDF Viewer, refer to the Lesson 2 - Loading 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.

runtime-pdf-viewer-zoom-factor-fit-visible-content

See Also