Skip to main content
All docs
V18.2

How to: Add a PDF Viewer to the WinForms Application via Code

  • 2 minutes to read

This example describes how to programmatically add a PDF Viewer to a Windows Forms application.

To add a PDF Viewer to the Windows Forms application at runtime, do the following.

  1. Run Microsoft® Visual Studio® 2012, 2013, 2015 or 2017.
  2. Create a new Windows Forms application project or open an existing one.
  3. Open the Solution Explorer, right-click References and choose Add Reference… to add references to the PDF Viewer libraries.

    PDFViewer_AddReference

  4. In the Extensions tab, select the DevExpress.XtraPdfViewer.v18.2, DevExpress.Pdf.v18.2.Core, DevExpress.Data.v18.2, DevExpress.Utils.v18.2 assemblies and click OK.

    ReferenceManager

  5. Write the following (or similar) code:

    
    using DevExpress.XtraPdfViewer;
    using System;
    using System.Windows.Forms;
    
    namespace CreatePdfViewer {
        public partial class Form1 : Form {
            public Form1() {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e) {
                // Create a PDF viewer.
                PdfViewer viewer = new PdfViewer();
    
                // Specify the viewer position on the form.           
                viewer.Dock = DockStyle.Fill;
    
                // Add the PDF viewer to the window.
                this.Controls.Add(viewer);
            }
        }
    }
    
  6. Run the application to see the result.

    AddPDFViewer_Result

See Also