Skip to main content
All docs
V24.2

Get Started with WinForms PDF Viewer (.NET)

  • 3 minutes to read

This tutorial illustrates how to use the WinForms PDF Viewer control (PdfViewer) to create a simple PDF Viewer application and adjust its appearance. The application targets .NET.

The following controls are used in this tutorial:

Design Time

Follow this step-by-step guide to create a PDF Viewer Application in Visual Studio:

  1. Run Microsoft Visual Studio and create a new Windows Forms App project.

  2. Install the following packages for your WinForms application:

    See the following help topic for details: Install NuGet Packages in Visual Studio, VS Code, and Rider.

  3. Drop the PdfViewer item from the DX.24.2: Common Controls toolbox tab onto the form.

    Drop the PDF Viewer Item onto the Form (.NET)

  4. Click the PDF Viewer’s smart tag and select Dock in parent container in the PDFViewer Tasks menu. This allows the PDF Viewer to expand to the form’s size.

    Dock the PDF Viewer In Parent Container (.NET)

  5. Create the Command UI. In the PDFViewer Tasks smart tag menu, select Create Ribbon to add a RibbonControl to the PdfViewer.

    Create Ribbon for the PDF Viewer (.NET)

  6. In the PdfViewer Tasks smart tag menu, select the required ribbon pages or click Create All Bars to add all available ribbon pages at once.

    Create All Bars for the PDF Viewer (.NET)

    You can customize the created ribbon afterward: change the ribbon style, add new ribbon elements, and modify or remove the existing items.

    You can also implement a bar interface. For this, select Create Bars instead of Create Ribbon. You can upgrade it to the ribbon interface at any time (for example, when converting the entire application).

  7. Load a document to the PDF Viewer. Click the PdfViewer’s smart tag to invoke its actions list. In the Actions list, click the Load PDF file… link.

    smart-tag-ribbon-load-pdf-file

    The Open dialog box appears. In this dialog, locate the document you want to display and click Open.

    LoadPDF OpenDialog

  8. Run the project to see the result: Result.

Runtime

  1. Run Microsoft Visual Studio and create a new Windows Forms App project.

  2. Install the following packages for your WinForms application:

    See the following help topic for details: Install NuGet Packages in Visual Studio, VS Code, and Rider.

  3. In the Form.Load event, use the following code to add PdfViewer to a WinForms application at runtime:

    using DevExpress.XtraPdfViewer;
    using System;
    using System.Windows.Forms;
    // ...
    private void Form1_Load(object sender,EventArgs e) {
        // Create a PDF viewer.
        PdfViewer pdfViewer = new PdfViewer();
        // Specify the viewer position on the form.
        pdfViewer.Dock = DockStyle.Fill;
        // Add the PDF viewer to the window.
        Controls.Add(pdfViewer);
    }
    
  4. To load a document, call the PdfViewer.LoadDocument() method: How to: Load a PDF Document from a File.

  5. Create the Command UI. Call PdfViewer.CreateRibbon() to add a RibbonControl to the PdfViewer at runtime.

    using DevExpress.XtraBars.Ribbon;
    using DevExpress.XtraPdfViewer;
    // ...
    //Create all PDF ribbon tabs
    pdfViewer.CreateRibbon();
    
    // You can also use an overload to specify which Ribbon tabs to add:
    // pdfViewer.CreateRibbon(PdfViewerToolbarKind.Main);
    

    You can also implement a bar interface instead of a Ribbon. For this, call the PdfViewer.CreateBars method.

Result

Run the application and try the PDF Viewer features. Load and navigate the document, highlight text, check the attachments, or print the result.

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

What’s Next