Jump to content

IE UDF displaying a PDF (and rotating it)


Go to solution Solved by NassauSky,

Recommended Posts

Yep, I'm liking the fact that i can still embed a very basic IE object in Autoit GUI in 2023.

For anyone still using this old method can anyone tell me why I can't extract html when I embed a PDF file into the object. Though I'm very interested in trying to manipulate the HTML and attempt a rotate using transform, I'm more interested in rotating the PDF so if there's another way I'm game.

 

#include <GUIConstantsEx.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
Example()

Func Example()
    Global $sPDF_path
    Global $Gui = GUICreate("PDF Viewer", 900, 600)
    GUISetBkColor(0xa0d0a0)

    Global $oIE = _IECreateEmbedded()
    GUICtrlCreateObj($oIE, 5, 5, 780, 590)
    Local $hButtonLoad = GUICtrlCreateButton("Load PDF", 795, 5, 100, 295)
        GUICtrlSetOnEvent(-1, "ButtonLoad")
    Local $hButtonExit = GUICtrlCreateButton("Rotate PDF", 795, 295, 100, 295)
        GUICtrlSetOnEvent(-1, "RotatePDF")

    GUISetState()
    GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
    Do
        Sleep(80)
    Until False
    GUIDelete()
EndFunc

Func ButtonLoad()
    $sPDF_path = FileOpenDialog("Select a PDF document", @ScriptDir & "\", "PDF (*.pdf)", $FD_FILEMUSTEXIST)
    If Not @error Then
            $oIE.Stop()
            $oIE.navigate($sPDF_path)
            while $oIE.Busy = true
                sleep(1000)
            wend;
            Local $oElements = _IETagNameAllGetCollection( $oIE )
            ;Local $oElements = _IETagNameGetCollection ( $oIE, "html" )
            For $oElement In $oElements
                ConsoleWrite(_IEPropertyGet($oElement, "innerHTML") & @CRLF &  "-----------------------------" & @CRLF)
            Next
            ConsoleWrite("!---END OF LOADED HTML---" & @CRLF)
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

Func RotatePDF()

EndFunc

 

For the curious, I still might go back to the adobe api but that crashed on me a couple times already and believe it or not it is not on most of my work computers since I have a less bloated reader on those machines.

 

 

Edited by NassauSky
Forgot to add the _Exit function
Link to comment
Share on other sites

@Andreik nice, it looks like you're trying to send Ctrl+Shift Plus combo. I didn't even realize that was a hotkey to do the magic.

I added the following to get confirmation it ran the control send (and changed $GUI definition to Global)
 

Func RotatePDF()
    ControlSend($Gui, '', 'AVL_AVView32', '^+{+}')
    MsgBox(0,"Notice", "Finished sending control sequence")
EndFunc

But no luck and nothing happened when I clicked rotate but I know you mentioned the option of using Adobe API and I tried it in the following code and it doesn't rotate the control but no luck again:
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$oPDF = ObjCreate("AcroPDF.PDF.1")
If Not IsObj($oPDF) Then
    MsgBox(16, "Error", "Failed to create AcroPDF object")
    Exit
EndIf

$oPDF.src = @ScriptDir & "\Pledge.pdf"
$oPDF.setShowToolbar(0)
$oPDF.setShowScrollbars(0)
$oPDF.setView('Fit')
$oPDF.setLayoutMode('SinglePage')
$oPDF.setPageMode('None')

$hMain = GUICreate('Test', 1280, 720, -1, -1, $WS_OVERLAPPEDWINDOW)
GUICtrlCreateObj($oPDF, 0, 0, 1280, 720)
GUISetState(@SW_SHOW, $hMain)

; Rotate the GUI window by 180 degrees
;DllCall("user32.dll", "int", "SetWindowPos", "hwnd", $hMain, "hwnd", 0, "int", 0, "int", 0, "int", 0, "int", 0, "int", 0x0036) ; SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED
Sleep(2000)
ControlSend($hMain, '', 'AVL_AVView32', '^+{+}')

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

But, I did test the control sequence manually on my keyboard and the hotkey combo worked successfully.  I'm going to see if I can target that control better with the correct class name since it's not a 32 bit control that was installed with Acrobat Reader.  Maybe I'll have to add an instance too. Will keep you posted...

Update: Turns out using IE embedded is running the Foxit Plugin and it also uses the same hotkey combo with different class names. OK so I'm still testing out how to send that control key to either option.

 

Thanks!

 

Edited by NassauSky
Link to comment
Share on other sites

  • Solution

OK got it, depending on your installed PDF plugin.

For Acrobat API:

Func RotatePDF()
  ControlFocus($hMain, '', '[CLASSNN:AVL_AVView33]')
  ControlSend($hMain, '', '[CLASSNN:AVL_AVView33]', '^+{+}')
EndFunc

or you'll have to wait for the control to be ready when you're initiating it without a button delay

ControlFocus($hMain, '', '[CLASSNN:AVL_AVView33]')
While Not ControlCommand($hMain, '', '[CLASSNN:AVL_AVView33]', 'IsEnabled', '')
    Sleep(100) ; Adjust the delay as needed
    ControlFocus($hMain, '', '[CLASSNN:AVL_AVView33]')
WEnd
ControlSend($hMain, '', '[CLASSNN:AVL_AVView33]', '^+{+}')

and if instead Foxit Reader:

Func RotatePDF()
    ControlFocus ( $Gui, '', '[CLASSNN:FoxitDocWnd1]')  ;FoxitDocWnd1
    While Not ControlCommand($Gui, '', '[CLASSNN:FoxitDocWnd1]', 'IsEnabled', '')
        Sleep(100) ; Adjust the delay as needed
        ControlFocus ( $Gui, '', '[CLASSNN:FoxitDocWnd1]')
    WEnd
    ControlSend($Gui, '', '[CLASSNN:FoxitDocWnd1]',  '^+{+}') ; !=Alt +=Shift ^=Ctrl
EndFunc


Thanks @Andreik

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