Sunday, February 26, 2006

Adobe Acrobat 7.0 Browser Control Type Library (ActiveX or COM)

Update: Please check out the other PDF related links in the sidebar as well.

Some horrors are erased!! Gasp !!

I came across the Adobe Acrobat 7.0 Browser Control Type Library that could be used to display and print PDF files on desktop (Windows forms) applications [I haven't explored utilizing this in a webpage, so that will have to wait]. This is really good stuff for some people, for it is an ActiveX control that you could utilize to automate certain PDF-related actions, instead of relying on the AcroRd32.exe process commandline options or DDE messaging (or worse - Win32 programming).

However, every approach has it's pitfalls.
And someone's already had a problem -

Bah. I can't believe that Adobe hasn't stepped up to hand out a library that will print any PDF with all of the printer settings available to be changed. (You apparently can create an Interop around their Acrobat TypeLib, but its features are limited and it can only print to the default printer.)

Oh well, that's why folks can charge lots of money for libraries I guess.


And if you have funds, then take this advice from an ex-Adobe employee a bit seriously, for he says -

I can give ya a little info on this as a former Adobe Employee and specifically dealing with Acrobat. They do have a SDK that allows you to work with PDFs but its not free, it does work in both managed and unmanaged code and they give some good examples done in C# and VB.net but here again its not free. I would look to some of the free PDF stuff and that may work but this is workable if you have the SDK because you can actually create a PDF object and load in that PDF and then use c# to print it like you would anything else.

Here's the CodeProject article utilizing the Adobe Acrobat 7.0 ActiveX object for communicating with Acrobat Reader, along with the .Net example utilizing the Browser Type Library that is described in the comments.

Ok, want to know more about this library ? Hop on and download the Adobe Acrobat Inter-Application Communication (IAC) Reference from the Adobe site (pdf download). The Acrobat Browser Type Library is provided by the AxAcroPDFLib.AxAcroPDF object. This should be suitable for most of your needs. You can access it by adding a reference to AcroPDF.dll (that resides in the ActiveX directory under the Acrobat application directory) in your IDE environment.

Technical Notes
  • If you dont want to display the PDF document in a Windows Forms application, then you'll have to set the 'Visible' property to false. And if you want to send the PDF file directly to the printer, then you could use one of the methods provided by the control for that purpose - Print, PrintAll, PrintAllFit, PrintPages, PrintPagesFit. That should be suitable for your silent print needs in most cases.
  • You could experience problems when you have to print to the default printer. The default printer seem to be determined by Acrobat when it is loaded, and not by Windows. So changing the default printer mid-way through your application's runtime might cause unexpected behavior.
  • It is impossible to "name" / "determine" the printer that is used to print the document. Unless you don't want the user to access all the printer settings that could change the workflow, the only solution is to use the PrintWithDialog method (which is used to present the Acrobat Print Dialog Box that allows the user to make changes to the number of copies to be printed, or print to a file).

And to help people searching for solutions to common problems involving Adobe Acrobat (even Reader), I'm posting a link to Experts Exchange's set of time-tested Adobe Acrobat solutions.

9 comments:

Anonymous said...

Hello mister, I want to use AcroPDF.dll (ActiveX for Acrobat Reader 7.0) in an application web ASP.NET 2.0.

My question, it is possible ?? What I can do about it ?

Thanks, mister. Greetings.

Unknown said...

Hi,
If you want to have it at the client-side, the best option is to go via JavaScript emitted out by ASP.Net; I think that is your intention though.
For server-side usage, all you'll have to do is install Adobe Acrobat reader on the server(!), and generate a COM interop dll to use it in your ASP.Net project. Registration of the COM interop dll is best done using a MSI installer, which can be done using Visual Studio.
Hope this helps.
Regards,
Vineet

Pingu said...

Hi. Can I use acrobat professional 7 to combine multiple documents from an ASP.net app? I added the COM object Adobe Acrobat 7 type library to my project. I don't know if this is the way and I want to know how can I use acrobat functionalities from my asp.net app.

Unknown said...

If you have Acrobat Professional 7 installed on the server, then your ASP.Net web application can utilize the type library to communicate with the Adobe app. However, it is doubtful whether the license of Acrobat Professional 7 allows for server side usage involving document generation.

Anonymous said...

Hi, I use AcroPDF.dll, i need open fdf file. it is possible?? how??

thank

Unknown said...

I'm afraid, I'll need more details to answer your question regarding the usage of Acropdf.dll to open FDF files. For instance, in what environment (Winforms app or JavaScript client) are you using the library ?

Steve said...

Hi
thanks for the information. I'm using the active x in a .net application. I noticed that it starts the acrord32.exe when my app starts. When I close my app the acrord32.exe continues to stay active in the task manager. Do you know of a way to prevent this from happening, without shutting down someones active adobe reader session in the off chance they have that open as well?

Thanks

Unknown said...

Hi Steven,
Since you're using COM interop, you'll have to release the COM object through a call to Marshal.ReleaseComObject. You can find more details in this MSDN article.
On the other hand, it could be an issue with Acrobat Reader itself. I remember this being the case with Acrobat Reader 6.0.

Anonymous said...

In reply to Steven's comment about closing the acrord32 process, see this thread in Adobe Forums - http://www.adobeforums.com/webx/.3bca1893

It seems that the process will kill itself after about 30 seconds if no longer needed - it works for me!