How to access Adobe Acrobat PDF functions?

Just starting out? Need help? Post your questions and find answers here.
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

How to access Adobe Acrobat PDF functions?

Post by RobertSF »

I can make PDFs show in a Web Gadget, and it works fine, but some have pointed out that user settings can affect this. So I wonder if anyone knows how to access the functionality that lies inside the basic Adobe Acrobat Reader, which almost everyone has on their computer.

In Visual Studio, I added a reference to Adobe Acrobat Browser Control Type Library. It appeared in the list of COM libraries. That somehow added AcroPDFLib to my references. It also added an AxAcroPDF "gadget" (Microsoft called them "controls") that I could drag on to my form. Then, in code, I could say,

Code: Select all

AxAcroPDF.LoadFile(PDFfileName$)
and the control would fill with the contents of the PDF and allow navigating it.

How to do this in PureBasic, aside from the Web Gadget way?
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to access Adobe Acrobat PDF functions?

Post by Shardik »

The following example works for me on Windows 8.1 x64 and Windows 10 x64 with PB 5.46 x86 in ASCII and Unicode mode. I utilize the DispHelper COM helper library which is 32 bit only, so my example doesn't work with x64 compilation. I utilize the DispHelper_Include.PB wrapper (DispHelper included) for creating the pdf COM object. Alternatively you could modify my example to use srod's COMatePLUS. You may also take a look into this older example from srod using the older COMate.

Code: Select all

EnableExplicit

#PDFFile = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Welcome.pdf"

IncludeFile "Path\to\DispHelper_Include.PB" ; <--- Modify path!

Define PDFFile.S = #PDFFile
Define PDFObject.I

OpenWindow(0, 0, 0, 1060, 806, "Welcome",
  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 10,
  #PB_Container_Double)
dhInitializeImp()
PDFObject = dhCreateObject("AcroPDF.PDF.1", GadgetID(0))

If PDFObject
  dhPutValue(PDFObject, "src = %B", StringToBSTR(PDFFile))
  SetActiveGadget(0)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
  dhReleaseObject(PDFObject)
EndIf

CloseWindow(0)
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: How to access Adobe Acrobat PDF functions?

Post by RobertSF »

Thank you so much, and 32-bit is fine!
Post Reply