Page 1 of 1

How to access Adobe Acrobat PDF functions?

Posted: Wed Feb 06, 2019 5:08 am
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?

Re: How to access Adobe Acrobat PDF functions?

Posted: Wed Feb 06, 2019 10:29 am
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)

Re: How to access Adobe Acrobat PDF functions?

Posted: Fri Feb 08, 2019 3:21 am
by RobertSF
Thank you so much, and 32-bit is fine!