Jump to content

Display PDF in GUI


mark2004
 Share

Recommended Posts

I would like to display a PDF file in a GUI (much like what is done with GUICTRLCREATEPIC and a jpg). I've searched the archives

and still haven't found a conclusive answer on this one.

Any ideas??

something like this?

#include <GUIConstants.au3>

;Vars
Dim $oMyError
Dim $File
Dim $Version

;Declare objects
$oPDF = ObjCreate("AcroPDF.PDF.1");

$Version=$oPDF.GetVersions
$oPDF.src="LittleBookOfRuby.pdf" ;PDF FILE 1
;Main Gui
GuiCreate("PDF Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUI_ActiveX = GUICtrlCreateObj ($oPDF, 10, 10 , 780 , 550)
GUICtrlSetStyle ( $GUI_ActiveX,  $WS_VISIBLE )
GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO)    ; Auto Resize Object
GuiSetState(@SW_SHOW)    

MsgBox(4096,"Show Versions",$Version)
    
GuiSetState(@SW_SHOWDEFAULT)

Sleep(1500)
$oPDF.src="test.pdf" ;PDF FILE 2

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
$oPDF = ""
$GUIActiveX = ""
Exit

;This is SvenP 's custom error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
Endfunc
Link to comment
Share on other sites

something like this?

#include <GUIConstants.au3>

;Vars
Dim $oMyError
Dim $File
Dim $Version

;Declare objects
$oPDF = ObjCreate("AcroPDF.PDF.1");

$Version=$oPDF.GetVersions
$oPDF.src="LittleBookOfRuby.pdf" ;PDF FILE 1
;Main Gui
GuiCreate("PDF Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUI_ActiveX = GUICtrlCreateObj ($oPDF, 10, 10 , 780 , 550)
GUICtrlSetStyle ( $GUI_ActiveX,  $WS_VISIBLE )
GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO)    ; Auto Resize Object
GuiSetState(@SW_SHOW)    

MsgBox(4096,"Show Versions",$Version)
    
GuiSetState(@SW_SHOWDEFAULT)

Sleep(1500)
$oPDF.src="test.pdf" ;PDF FILE 2

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
$oPDF = ""
$GUIActiveX = ""
Exit

;This is SvenP 's custom error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
Endfunc

Very cool example - Thanks (ottimo esempio - Grazie)

Peppe

Link to comment
Share on other sites

Thanks very much. I was looking for a way to do it without using adobe's reader and i figured out that this basically boils

down to converting the pdf to a jpg first, then using GuiCtrlCreatePic. This way you don't have the menus etc associated with

embedding an app in the GUI.

Very cool code snippet. Its a great example of how to use ActiveX....I will probably refer to it often.

something like this?

#include <GUIConstants.au3>

;Vars
Dim $oMyError
Dim $File
Dim $Version

;Declare objects
$oPDF = ObjCreate("AcroPDF.PDF.1");

$Version=$oPDF.GetVersions
$oPDF.src="LittleBookOfRuby.pdf" ;PDF FILE 1
;Main Gui
GuiCreate("PDF Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUI_ActiveX = GUICtrlCreateObj ($oPDF, 10, 10 , 780 , 550)
GUICtrlSetStyle ( $GUI_ActiveX,  $WS_VISIBLE )
GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO)    ; Auto Resize Object
GuiSetState(@SW_SHOW)    

MsgBox(4096,"Show Versions",$Version)
    
GuiSetState(@SW_SHOWDEFAULT)

Sleep(1500)
$oPDF.src="test.pdf" ;PDF FILE 2

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
$oPDF = ""
$GUIActiveX = ""
Exit

;This is SvenP 's custom error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
Endfunc
Link to comment
Share on other sites

  • 4 months later...

Thanks very much. I was looking for a way to do it without using adobe's reader and i figured out that this basically boils

down to converting the pdf to a jpg first, then using GuiCtrlCreatePic. This way you don't have the menus etc associated with

embedding an app in the GUI.

Very cool code snippet. Its a great example of how to use ActiveX....I will probably refer to it often.

Cool :)

It´s Only Rock´n´Roll, But I Like It
Link to comment
Share on other sites

  • 1 month later...

I get the following error when I try to run the script example shown.

C:\Program Files\AutoIt3\Examples\GUI\Advanced\PDF in GUI2.au3 (11) : ==> Variable must be of type "Object".:

$Version=$oPDF.GetVersions

$Version=$oPDF^ ERROR

Do I need a specific version of Acrobat reader?

Link to comment
Share on other sites

I keep getting File does not begin with '%PDF-'. and then an empty window. Any ideas? I found this while Googling, but the files I'm trying work fine if I open them normally. Heck, the file I'm trying to open is "C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf" ... that's the HELP FILE for Acrobat! Hahaha. I only have problems if I try and open them with AutoIt.

Hmm.. just to double check, I opened the file with a hex editor, and it does start with %PDF-. Now I'm really stumped. :\

Link to comment
Share on other sites

$oPDF = ObjCreate("AcroPDF.PDF.1");

This is nice.

Can be this PDF COM object downloaded from somewhere without buying full Adobe Acrobat?

Is it in Adobe Acrobat Reader (not editor) install package?

Works with Acrobat and Reader (versions >= 7). Will be installed from both apps.

br, Reinhard

Link to comment
Share on other sites

I get the following error when I try to run the script example shown.

C:\Program Files\AutoIt3\Examples\GUI\Advanced\PDF in GUI2.au3 (11) : ==> Variable must be of type "Object".:

$Version=$oPDF.GetVersions

$Version=$oPDF^ ERROR

Do I need a specific version of Acrobat reader?

Also with Acrobat/Reader 7 and higher you get this error message if the viewer is not configured to show the PDF in (IE) Browser, what normally is set as standard.

Under "Edit" choose "BasicSetting" (last menuitem), select "Internet" and then mark [x] PDF in Viewer (MenuItem Free translated from a german version).

For scripter this means, if you want to make shure that "embedded" works, you first have to check/influence the registry key.

HTH, Reinhard

Edited by ReFran
Link to comment
Share on other sites

Does this IE based solution work for you?

#include <GUIConstants.au3>


$Form1 = GUICreate("Browse PDF", 400,300,400,300) 
$Obj = ObjCreate("Shell.Explorer.2")
$browser = GUICtrlCreateObj($Obj, 0, 0, 400, 300)
GUISetState(@SW_SHOW)
$Obj.Navigate('C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf')
;; $Obj.Navigate('C:\Programme\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf')

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
;;;;;;;
    EndSelect
WEnd
Exit
Edited by ReFran
Link to comment
Share on other sites

Yup that works fine. Unfortunately doesn't help with what I needed, cus I was trying to avoid using IE, but thank you.

My reader version is 7.0.0.0.

You should update (see under help) at least to 7.0.9.

However, with an embeded object like Reader and some other -direct with dll or indirect with IE - you get a repain problem.

There has been a discussion here about this, but no solution.

So I start it direct and move it to the position and size I want and influence the Reader direct.

HTH, Reinhard

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...