Jump to content

Recommended Posts

Posted

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

Posted

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
Posted

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

Posted

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
  • 4 months later...
Posted

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
  • 1 month later...
Posted

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?

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
Posted

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. :\

Posted

$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

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
Posted

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

Posted

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.
Posted

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

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
Posted

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

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
  • Recently Browsing   0 members

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