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

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

  1. Run Microsoft® Visual Studio® 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.18.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 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

    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

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.

    PDFVIewer_GettingStarted_ProjectSettings

    Call the UserLookAndFeel.Default static object’s UserLookAndFeel.SetSkinStyle method:

    
    using DevExpress.LookAndFeel;
    // ...
    UserLookAndFeel.Default.SetSkinStyle("Office 2019 Colorful", "Fire Brick");
    
  • Change the PDF Viewer’s skin

    Use the LookAndFeel property to access an object specifying the control’s look and feel settings.

    
    pdfViewer.LookAndFeel.UseDefaultLookAndFeel = false;
    pdfViewer.LookAndFeel.SkinName = "Office 2016 Colorful";
    
  • 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
    PDFViewer_Ribbon_SVG
    Bitmap Icons
    PDFViewer_Ribbon_Bitmap

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

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

See Also