Saturday 7 December 2013

Display PDF On Form Using Adobe PDF Reader In C#

Right Click On Toolbox 'Data' Controls And In The Displayed Pop-up Click On 'Choose Items...' As Shown Below:

Now 'Choose Toolbox Items' Dialog Box Will Displayed


In The 'Choose Toolbox Items' Select 'COM Components' Tab And Tick The Checkbox Of 'Adobe PDF Reader' And Click On 'Ok' Button.


In Toolbox 'Data' Controls 'Adobe PDF Reader' Is Added And Click The 'Adobe PDF Reader' And Place It On Form1 As Shown Below:


Now Place A Button On The Form And Named It 'btnShow'  As Shown Below:


Now Write The Below Code In Form1.cs

using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;

namespaceShowPDFFileInAdobeReader
{
    public partial class Form1 : Form
    {
        publicForm1()
        {
            InitializeComponent();
        }
       
        privatevoid btnShow_Click(objectsender, EventArgs e)
        {
            stringpath1 = "C:\\ShowPDFFileInAdobeReader\\RamachandraExceptions.pdf";
          
           
           axAcroPDF1.src = path1;

            /* or  */

           /* string path1 = "..\\RamachandraExceptions.pdf";  //Path Should Be Given Like This If The PDF File Is Beside The Debug Folder And In The Bin Folder Of The Project
            axAcroPDF1.LoadFile(path1);     */


        }
       

    }
}

Note :-

If axAcroPDF1.LoadFile(path1); Path Should Be Given as string path1 = "..\\01Ashwini.pdf"//If The PDF File Is Beside The Debug Folder(In Which EXE File Exists) And In The Bin Folder Of The Project As Shown Below : 





If axAcroPDF1.src = path1; Full Path Should Be Given as string path1 = "C:\\ShowPDFFileInAdobeReader\\RamachandraExceptions.pdf"


Now Run The Project And Click On The "Show" Button It Gives The Following Output:

Output:-


No comments:

Post a Comment

Note: only a member of this blog may post a comment.