tags:

views:

978

answers:

7
+1  A: 

I would suggest converting your pdf file to a Microsoft help file, so that you don't need to have Adobe Reader installed (it's buggy, and has way too much security issues). You cannot expect users to have this.

In reply to the starter's comment:

Yes you would need to create your help file as an HTML document instead of a pdf. There is no easy way to convert pdf to HTML.

Snake
Hmmmmmm.... I do agree with u that I can't expect users to have pdf reader installed, but bcoz I'm just a learner so this simple "calculater utility" is not expected to be widely spread (popular) application. I'm just learning to code.....I had just installed Microsoft help file creator also but I'm not able to use it easily. Its asking for html files (input). I think I need to carefully see everything inside this help file creator.
gsvirdi
+1  A: 

It might be possible to embed Adobe's Reader in your form as an ActiveX component. But that means you'll have to make sure Reader is installed on the client machine for that to work.

In case it doesn't have to be strictly embedded you can just launch the PDF file and let whatever viewer the user has open it.

Assaf Lavie
Even if Adobe reader is not installed I think we can take care of this case with the Try {} catch {} thing and Pop a message in case the reader is not there. No worries. The only thing I'm wondering is the use of "Embedding" a file into the exe and displaying it without providing it on the user's hard disk as a separate file.
gsvirdi
+1  A: 

I would put it on within my program folder, add a link within my Start Menu folder to allow a direct access (without starting my tool) and just at on some click event System.Diagnostics.Process.Start(@".\Manual.pdf");

Update

Ok, now we come to a completely new question: How to embed a file in my application and start it?

For this question you'll find already several answers here, but here is the short version:

  1. Right click your project and select Add - Existing Item
  2. Select your file (don't double click it)
    • Click the little arrow next to the Add button and select Add As Link
  3. Double click on Properties - Resources.resx
  4. Click the little arrow next to Add Resource and select Add Existing File
  5. Select the same file again in the open dialog
  6. Now you can access the file within your code as byte[] from Properties.Resources.NameOfResource

With these steps you reference your file where ever it exists within your structure. If you like that a copy of your pdf file will be put into a subfolder Resources within your project, just skip the points one and two in the above list.

To get your pdf now opened, you'll have to write the byte[] down to disk (maybe with Path.GetTempFileName()) and start it with Adobe Reader. (Don't forget to delete the file after usage)

Oliver
I agree that the Process method works perfetly. Process.Start("C:\\Documents and Settings\\gsv\\Desktop\\manual.pdf");But as I said... in that case I will need to provide a separate pdf file with this calculator.exe Is it possible to embed the file into the exe itself???
gsvirdi
+2  A: 

You could use the WebBrowser control and let IE load a PDF reader for you if there is one installed on the machine.

However the last time I tried this, I had to write the PDF file to disk first, so I could point the WebBrowser control at it.

Ian Ringrose
Not very nice if your users prefer Firefox ;-)
Winston Smith
@Winston, as the WebBroser control does not have the IE toolbars, if you disabled the right click menu most users will not be able to tell it is IE.
Ian Ringrose
@Ian This sounds simple...... So how u did it? I think to achieve this I would need to bundle the file with the application. Then on "Button click" event the application (.exe) should check with>>> if (File.Exists("user manual.pdf")) // then display else //extract the pdf to the same directory. //and then display it in the browser. I know about "add an existing item as reference, but how to copy it to the output directory via C# code?
gsvirdi
+8  A: 

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;
Winston Smith
not very nice if your users has chosen to use a 3rd party control to read pdf documents.
Ian Ringrose
@Ian Are you suggesting that a *WinForms Calculator Application* should inherit configuration from IE on the same machine? I hope not.
Winston Smith
deos the Adobe Reader ActiveX control work with "register free com", or will a user need to install it?
Ian Ringrose
@Winsten, No but it should not change the PDF reader that IE/Firefox has been setup to use, installing Adober reader when the app is installed may change all sorts of settings (knowing Adobe!)
Ian Ringrose
@Ian - The users settings certainly **will not** be changed, nor will Adobe reader be installed. This approach simply means bundling two DLLs with your application (`AxInterop.AcroPDFLib.dll` and `Interop.AcroPDFLib.dll`) which it uses to display the PDF.
Winston Smith
+2  A: 

If your user has Adobe Reader (or any other PDF reader) installed on their machine, you could use:

System.Diagnostics.Process.Start(
       "My-PDF-file.pdf");

Hope this helps.

Note: Obviously, this will fail if the user does not have any PDF Reader applications installed.

Tommy
I agree that the Process method works perfetly. Process.Start("C:\\Documents and Settings\\gsv\\Desktop\\manual.pdf"); But as I said... in this case I will need to provide a separate pdf file with this calculator.exe!!!! Is it possible to embed the file into the exe itself??? Then on "Button_Click" event the application can extract the pdf into the same folder and then display it? How to extract the file into the same user's directory?
gsvirdi
Ah, yes - this is possible. But since I couldn't get it working properly, I wouldn't recommend it.
Tommy
This worked perfectly for what I needed! Thanks. +1
Mike Wills
+1  A: 

There is a C# pdf viewer project on google code. http://code.google.com/p/pdfviewer-win32/ there is the viewer and there is the library that it uses available that uses mupdf and xpdf to render the pdf documents in your winforms program. I am currently developing a User control library for people to use and drop into their programs for pdf viewing capabilities. it works pretty good.

cferbs