Sign in to follow this  
Followers 0
mark2004

Display PDF in GUI

21 posts in this topic

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??

Share this post


Link to post
Share on other sites



Try loading the ActiveX for Adobe. I can't tell you much about it because I don't use ActiveX.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Cool :)


It´s Only Rock´n´Roll, But I Like It

Share this post


Link to post
Share on other sites

How are you converting it to a JPG? If you have the ability to read it, why not output it in a text based format instead?

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

If I remember right you need a Version >= 7 (Acrobat or Reader).

HTH, Reinhard

PS: By the way you shouldn't use .. = $oPDF.GetVersions. Adobe will discontinue, but in actual versions it works.

Edited by ReFran

Share this post


Link to post
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. :\

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Anybody else have the same problem as me?

Share this post


Link to post
Share on other sites

Anybody else have the same problem as me?

I don't know what the problem is, but what happens if you type: "C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf"

into the IE address line.

Reinhard

Share this post


Link to post
Share on other sites

I don't know what the problem is

I keep getting File does not begin with '%PDF-'. and then an empty window. :)

but what happens if you type: "C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf"

into the IE address line.

It displays the PDF file in the browser frame.

Share this post


Link to post
Share on other sites

I keep getting File does not begin with '%PDF-'. and then an empty window. :)

It displays the PDF file in the browser frame.

Which Acrobat/Reader version (exact) you work with.

Can you show your code-snippet you work with.

br, reinhard

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0