tags:

views:

144

answers:

5

Hey guys, 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.

+1  A: 

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.

David Stratton
+5  A: 

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();
    
Darin Dimitrov
I'll vote that up because it will work.. Although I think using the WebBrowser control is simpler.
David Stratton
@David, while `WebBrowser` approach is indeed easier to implement it gives you little control over the PDF compared to the Adobe component which allows you to navigate, print, ...
Darin Dimitrov
Awesome! but is it possible for me to distribute the correct library as well? The installer should do the work. What about a lightwieght pdf reader like foxit, can it be used similarly?
masfenix
The installer should include the COM interop wrapper assemblies but the end users will need to have Adobe Reader installed for the application to run. As far as Foxit is concerned I've heard that they also provide an AtiveX control but never used it and cannot give you much info.
Darin Dimitrov
Is it possible my installer then install adobe reader as well?
masfenix
I am not sure that this is legally right. You could though write a custom install step that verifies if Adobe Reader is installed and if not prompt the user to download it from the official site. Or if Adobe allows it include the installer binaries and simply run it from within your installer.
Darin Dimitrov
+1  A: 

I've had very good experiences working the the Aspose libraries. They're affordable and will save you a lot of time.

Tyler Jensen
+1  A: 

You can embed Adobe Reader in your apps via the ActiveX component that is installed on your machine along with the reader. You can add it to your VS Toolbox from the COM Components tab. Anyone who has Abobe Reader installed will then be able to use your app to view PDF documents. Note that if there is not Adobe Reader installed your program will not work, or you need somehow to provide the lib with the application. If you want something that does not require Adobe Reader then you may like to check out the iText#.

Incognito
Drawback is hat your app wont work on machines that don't have adobe reader installed. I guess the OP is only building something for a friend, but I would be quite unhappy if I had to install adobe reader just to use some other application...
Ben Schwehn
Acutally, the friend is a contractor to a bigger company. The company will need to distribute this out to their clients and well, they can't ship something out if it dosnt work.
masfenix
The company then even less can distribute adobe libraries without permission from adobe (normal redist license allows only to redistribute a full installer: http://www.adobe.com/products/reader/rdr_distribution1.html). I would expect foxit to have similar requirements
Ben Schwehn
@masfenix If the application must be distributed to others may be it would be better ti have a look at iText#.
Incognito
A: 

A potential problem with using a Adobe ActiveX/com component is that the user must have Adobe Reader installed for this to work (I don't think you're able and/or allowed to redistribute the activeX control only and wouldn't want to force my users to install Adobe Reader). So for more serious work I would try to use a Pdf library that you can distribute with your code such as writing a (presumably very small) P/Invoke wrapper for the open source library http://ccxvii.net/mupdf/ or if you can/want afford it use some commercial library.

An problem with using a webbrowser control is that you have to be careful to test what happens if a target user as embedding of pdf disabled in IE. It can happen that instead of embedding you get a external adobe reader (or whatever is registered as pdf handler) pop up! There might be a workaround, but I've been bitten by this before (resulting in one of those "works on my machine" problems)

Ben Schwehn
The problem with this is that the library dosn't support the PDFs that have links embedded or textboxes, etc. or does it?
masfenix
Well, that would depend on the library :) I'm not sure about mupdf to be honest, but IIRC sumatrapdf is based on mupdf and sumatra at least supports embedded links, ToC and bookmarks. Tyler Jensen mentioned Aspose, I guess that would support more advanced pdf features but I've never used it myself and it's a bit expensive... For mupdf I guess you could simply try and see if sumatrapdf supports the features you need, then investigate how much effort a P/Invoke layer for .net would be.
Ben Schwehn
Oh and of course mupdf is GNU GPL3 ("For commercial licensing please contact [email protected]."). So you'd definitely have to make sure you comply with the terms of the license
Ben Schwehn