Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Easiest Way to Show PDF File in Delphi Application

delphi pdf adobe acrobat reader activex control

  • Please log in to reply
No replies to this topic

#1 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 24 February 2013 - 12:29 AM

Overview

The popularity of PDF file sometimes forces us to use it in our Delphi application. There is actually a benefit for this. You could get better look from the PDF (since it might contains graphics, creative formatting of texts, etc.) without fancy coding. Instant good looks!

For you who do not familar with PDF file, please visit this wikipedia page for more information. But basically PDF (Portable Document Format) is (quoted from wikipedia):

 

a file format used to represent documents in a manner independent of application software, hardware, and operating systems.[1] Each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, graphics, and other information needed to display it.

 

It used to be propietary format owned by Adobe. But in 2008 Adobe released it to public as open standard. And now the maintenance and further development of this format is controlled by ISO.

In this tutorial I will show you how to show PDF file(s) in your Delphi application, the easy way. But I must warn you, easy way does not mean the best way.


Basic Steps

a file format used to represent documents in a manner independent of application software, hardware, and operating systems.[1] Each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, graphics, and other information needed to display it.

  • Install Adobe Reader. This step actually optional. You don't have to do this if you already have Adobe Reader installed in your machine.
  • Import Adobe Reader activeX to your Delphi environment.
    Upon installation, Adobe Reader installer will also register an ActiveX control to your Windows. You can import it to your Delphi as new control.

    For you who does not familiar with importing ActiveX control, follow the following procedure. It is with Delphi 7, but the general steps should be applicable to other Delphi versions.
    • Open menu item Component > Import ActiveX Control.... Like shown below.
      Preparation001_ImportActiveXMenu.png
    • In Import ActiveX dialog that follows, find Adobe Acrobat 7.0 Browser Control Type Library (Version 1.0) (the actual name in your computer might be slightly different, since it depends on the Acrobat Reader version actually installed in your system). The rest of the edit boxes will be filled with default values. Like shown below.
      Preparation002_ImportActiveXDialog.png
    • Click on Install... button to start installing the imported ActiveX into our Delphi component libraries. Like shown below.
      Preparation003_ImportActiveX_StartInstallControl.png
    • Simply click OK to store the imported Acrobat Reader control in Delphi default user components package (dclusr.dpk).
      You will be asked to confirm the rebuilding of dclusr.dpk package. If you give the confirmation, Delphi will rebuild and recompile dclusr.dpk and imported controll will in our component pallete.
    • After the previous step, you may want to inspect ActiveX tab in our component pallete to see if the Acrobat Reader control has been imported and installed properly. Like shown below.
      Preparation0040_ImportActiveX_CheckActiveXPallete.png
  • Note that if you don't change the default, the imported Adobe Reader control class will be named TAcroPDF. And from now we will use this class name.
  • Drop TAcroPDF control to your form.
  • Use either src property or LoadFile method of TAcroPDF to load a pdf file into it. From my experience, I strongly recommend to use src property. It's more flexible since with it you can use url to specify the file and also you can add extra parameters to control how the file should be loaded.
  • And that's it! Now you can easily show pdf files inside your Delphi applications.


    Demo Project

    I have written a simple Delphi application to show you to use TAcroPDF. Full source code attached. Along with the zipped source code, I also included a pdf sample and another pdf that contains information of extra parameters for opening a pdf file. You may want to experiment with it. The original url of that open parameters document is here.

Attached Files


Edited by LuthfiHakim, 24 February 2013 - 08:18 PM.

  • 1





Also tagged with one or more of these keywords: delphi, pdf, adobe acrobat reader, activex control

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download