Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a pdf file from Winform

Tags:

I'm just creating a simple calculator in C# (windows form)

I've created a "User Help" which is a pdf file, what I want is to display that pdf file if the user clicks on the "Help" button in the WinForm. If assumed that Adobe reader is pre-installed on the user's machine....

How to open the pdf file on button click in winForm?

I don't plan to provide this pdf file on hard disk of user. Which means that I have to embed this pdf into the calculator (winForm) and have to display it on the button click.

Kindly guide me with the best practise for displaying an embedded file in winForm.

like image 711
gsvirdi Avatar asked Feb 08 '10 07:02

gsvirdi


People also ask

Why can't I display a PDF?

Here are some of the most common culprits to consider: Your laptop doesn't have a PDF reader installed. Your PDF reader or preferred program is out of date and needs an update. Your PDF application is potentially damaged or needs to be rebooted.


1 Answers

You can reference the Adobe Reader ActiveX control and bundle it with your application.

Simply add AcroPDF.PDF.1 to your Toolbox from the COM Components tab (right click toolbox and click Choose Items...) then drag an instance onto your Winform to have the designer create the code for you. Alternately, after adding the necessary reference you can use the following code:

AxAcroPDFLib.AxAcroPDF pdf = new AxAcroPDFLib.AxAcroPDF(); pdf.Dock = System.Windows.Forms.DockStyle.Fill; pdf.Enabled = true; pdf.Location = new System.Drawing.Point(0, 0); pdf.Name = "pdfReader"; pdf.OcxState = ((System.Windows.Forms.AxHost.State)(new System.ComponentModel.ComponentResourceManager(typeof(ViewerWindow)).GetObject("pdfReader.OcxState"))); pdf.TabIndex = 1;  // Add pdf viewer to current form         this.Controls.Add(pdf);  pdf.LoadFile(@"C:\MyPDF.pdf"); pdf.setView("Fit"); pdf.Visible = true; 
like image 193
Winston Smith Avatar answered Sep 21 '22 06:09

Winston Smith