Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hosting a PDF in a c# application

Tags:

c#

pdf

I am creating an ebook for a friend. He has the content in word (docx) so I have a few questions. I created a thread earlier on how to approach this and the best response was to create PDF's out of it. The main point of this was so we can have insertable textboxes, links, and table of contents.

Now I was wondering if I can host the pdfs in my application. I want to make an "adobe reader" basically. Is there a library out there that does this? Can I use installed COM/dlls to do this?

The reason for this is that I was to create like a "quiz" section on my application, or a "report card" or even a "bookmark" feature.

Thanks guys.

like image 367
masfenix Avatar asked Jul 18 '10 19:07

masfenix


2 Answers

Making a custom PDF browser control could be an extremely challenging task. You could instead use the real Adobe Reader in your application as it is provided as a COM control which could be hosted in any Windows application. Here are the steps:

  1. Start a new WinForms application
  2. Make the Acrobat control available in the toolbox (Tools -> Add/Remove Toolbox Items: turn on "Adobe Acrobat 7.0 Browser Document" in COM Components tab). Don't forget to grab a cup of coffee before clicking on the COM tab.
  3. Drag the control to the form
  4. Manipulate it:

    axAcroPDF1.LoadFile("mypdf.pdf");
    axAcroPDF1.Show();
    
like image 63
Darin Dimitrov Avatar answered Oct 07 '22 05:10

Darin Dimitrov


I know this has been asked before, but I can't remember where. The accepted answer was something along these lines:

It would be a very bad idea to create your own PDF reader, because:

  1. you are not in control of when Adobe changes specs
  2. Adobe provides a reader free of charge, and most users already have it installed.
  3. Given the previous two statements, why would you want to spend that much time on reinventing the wheel? It makes sense to reinvent the wheel when you can improve upon it, but not when you are just copying functionality that is freely available.

It would be far better to find a way to use the Acrobat reader that they have already designed, and distribute free of charge.

This is very easy to do. All you need to do us use the WebBrowser control (assuming this is WinForms) and set the DocumentSource to the PDF file. The WebBrowser control will just automatically use whatever pdf reader is already installed on the client PC, just as would Internet Explorer.

like image 22
David Avatar answered Oct 07 '22 05:10

David