C# How to display a PDF file from Windows app?

Posted on 2005-05-05
Last Modified: 2011-08-18
My Windows app has a help file in PDF format.
How do I display this file when user clicks on Help command?
Question by:rj94070
    LVL 19

    Accepted Solution

    Add Adobe Acrobat as a COM reference.

    private AxAcroPDFLib.AxAcroPDF axAcroPDF1;

    when the user hits the help button, have it do a axAcroPDF1.LoadFile() command.

    Here is a small C# program I wrote to load PDF's and turn off the PDF Toolbar.  REMEMBER:  You must first load the reference into the object browser for that project.

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace PDFApp
          /// <summary>
          /// Summary description for Form1.
          /// </summary>
          public class Form1 : System.Windows.Forms.Form
                private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
                private System.Windows.Forms.OpenFileDialog ofnDialog;
                private string strFileName = null;
                private bool bToolBarState = false;
                private System.Windows.Forms.Button btn_browse;
                private System.Windows.Forms.Button btn_toggletb;
                /// <summary>
                /// Required designer variable.
                /// </summary>
                private System.ComponentModel.Container components = null;

                public Form1()
                      // Required for Windows Form Designer support
                      axAcroPDF1.Visible = false;

                      // TODO: Add any constructor code after InitializeComponent call

                // Run an Open File Dialog which we'll likely not use in
                // Amici but I need it for testing.
                public int PDFDoOpenFileDialog()
                      ofnDialog.FileName = "";
                      if (ofnDialog.ShowDialog() == DialogResult.OK)
                            strFileName = ofnDialog.FileName;
                            axAcroPDF1.Visible = true;
                            return 1;
                            return 0;

                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                protected override void Dispose( bool disposing )
                      if( disposing )
                            if (components != null)
                      base.Dispose( disposing );

                #region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
                      this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
                      this.ofnDialog = new System.Windows.Forms.OpenFileDialog();
                      this.btn_browse = new System.Windows.Forms.Button();
                      this.btn_toggletb = new System.Windows.Forms.Button();
                      // axAcroPDF1
                      this.axAcroPDF1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                            | System.Windows.Forms.AnchorStyles.Left)
                            | System.Windows.Forms.AnchorStyles.Right)));
                      this.axAcroPDF1.Enabled = true;
                      this.axAcroPDF1.Location = new System.Drawing.Point(40, 80);
                      this.axAcroPDF1.Name = "axAcroPDF1";
                      this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));
                      this.axAcroPDF1.Size = new System.Drawing.Size(704, 448);
                      this.axAcroPDF1.TabIndex = 0;
                      // btn_browse
                      this.btn_browse.Location = new System.Drawing.Point(40, 24);
                      this.btn_browse.Name = "btn_browse";
                      this.btn_browse.Size = new System.Drawing.Size(80, 32);
                      this.btn_browse.TabIndex = 1;
                      this.btn_browse.Text = "Browse";
                      this.btn_browse.Click += new System.EventHandler(this.btn_browse_Click);
                      // btn_toggletb
                      this.btn_toggletb.Location = new System.Drawing.Point(656, 24);
                      this.btn_toggletb.Name = "btn_toggletb";
                      this.btn_toggletb.Size = new System.Drawing.Size(80, 32);
                      this.btn_toggletb.TabIndex = 2;
                      this.btn_toggletb.Text = "Toolbar";
                      this.btn_toggletb.Click += new System.EventHandler(this.btn_toggletb_Click);
                      // Form1
                      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                      this.ClientSize = new System.Drawing.Size(776, 550);
                      this.Name = "Form1";
                      this.Text = "Form1";
                      this.Load += new System.EventHandler(this.Form1_Load);


                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                static void Main()
                      Application.Run(new Form1());

                private void btn_browse_Click(object sender, System.EventArgs e)

                private void Form1_Load(object sender, System.EventArgs e)
                      ofnDialog.Filter = "Adobe Acrobat Documents(*.pdf)|*.pdf" ;
                      ofnDialog.FilterIndex = 1;

                private void btn_toggletb_Click(object sender, System.EventArgs e)
                      bToolBarState = !(bToolBarState);
    LVL 14

    Assisted Solution

    You can also use:

    This should launch Acrobat Reader with your pdf in it. A con is that it wont load as a part of your application though.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This is an explanation of a simple data model to help parse a JSON feed
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now