Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2005-05-05
Medium Priority
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 20

Accepted Solution

Daniel Van Der Werken earned 1000 total points
ID: 13938036
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

existenz2 earned 1000 total points
ID: 13938104
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
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…
Screencast - Getting to Know the Pipeline

571 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