Jump to content

Embed pdf in a GUI


myspacee
 Share

Recommended Posts

Hello to all,

to automate process in office i must list all pdf in a directory

and give to my user preview of selected pdf to do some task.

My user are not so smart to apply all rules (naming convention, path, etc.)

so I want to guide their job.

There is any way to have pdf preview directly in AutoIt gui?

Thank you for any info,

m.

Link to comment
Share on other sites

In Linux*, you can just use convert:

convert -thumbnail x150 MyPDF.pdf[0] MyPDF_Thumb.bmp

This capability is ported to Windows as ImageMagick: convert.

For extreme AutoIt geekiness, it even comes as a COM interface: Introduction to the ImageMagickObject COM+ Object

:mellow:

*Note: Actually, convert and various other command line utilities are installed by the ImageMagick package too.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I was thinking of preview thumbnails for multiple docs, but on re-reading the OP this is probably closer to what's wanted.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

First of all thank you all for reply.

Before make this post i've searched on forum and find some of link you suggest.

Think was simple task but i'm wrong, PDF are not images and initially I use image approach.

I want to use Windows and it's preview feature, to load pdf as images. Without luck.

So post this simple request for heavy problem.

Understand that Adobe activex was free (read until reader version 6.0) and then

adobe ask for money.

Follow link you suggest find Melba working code for pdf previewing:

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

; Install a custom error handler
Global $oMyError = ObjEvent("AutoIt.Error","_ComErrFunc")

_Show_PDF()

Func _Show_PDF()

    ; Get file to display
    Local $sFile = FileOpenDialog("Choose PDF", "M:\Documents", "PDF Files(*.pdf)", 3) ; put your own start folder here
    If @error Then
        MsgBox(0, "Error", "No file selected")
        Return
    EndIf

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

    ; Create GUI
    GUICreate("AutoIt PDF Reader", 1000, 570)
    Local $GUI_ActiveX = GUICtrlCreateObj($oPDF, 10, 10, 780, 550)
    GUICtrlSetStyle($GUI_ActiveX, $WS_VISIBLE)
    GUICtrlSetResizing($GUI_ActiveX, $GUI_DOCKAUTO) ; Auto Resize Object
    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        
    WEnd

    ; Clear up
    $oPDF = ""
    $GUIActiveX = ""

    Exit

EndFunc

Not start yet to try coding, but do you think is possible to have directory list,

where new file selection load/refresh pdf into same GUI?

Can i ask you a little more help?

thank you,

m.

Link to comment
Share on other sites

Since the Adobe solution is for-cost if you want to use a COM interface, and since ImageMagick is open source and free, you still might want to look at that option.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Find COM for imagmagick in forum:

http://www.autoitscript.com/forum/index.php?showtopic=49065&hl=imagemagick%20com&st=0

But i've not idea how to use it to display pdf in a GUI, isn't it a image conversion utility ?

Find also some Adobe example for VB... (i hate it)

m.

Edited by myspacee
Link to comment
Share on other sites

Yes, it's an image conversion utility, but one of the conversions it can do is into a thumbnail, including a thumbnail of only the first page of a PDF file. The idea was to get your list of files, create a thumbnail of each with ImageMagick (say, BMP files) and use those thumbnail files in your AutoIt GUI.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Never said it didn't, but that displays a single document in an embedded instance of Reader, doesn't it? I'm still looking at producing multiple thumbnail images that could be included in an AutoIt GUI "picker". This was what I expected to produce the thumbnails as jpg files:

#include <File.au3>

Global $oMyError, $oImgMgk, $RET
Global $sPdfDir, $aPdfFiles, $sPdfFile, $sBmpFile

; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

; Get folder to search
$sPdfDir = FileSelectFolder("Select folder with PDF files", "")
If @error Then Exit

; List PDF files in folder
$aPdfFiles = _FileListToArray($sPdfDir, "*.pdf", 1) ; 1 = files only
If @error Then
    MsgBox(16, "Error", "Error listing PDF files at:  " & $sPdfDir)
    Exit
EndIf

; Get COM object for ImageMagick
$oImgMgk = ObjCreate("ImageMagickObject.MagickImage.1")

For $n = 1 To $aPdfFiles[0]
    $sPdfFile = $sPdfDir & "\" & $aPdfFiles[$n]
    ConsoleWrite("$sPdfFile = " & $sPdfFile & @LF)
    $sBmpFile = $sPdfDir & "\" & StringTrimRight($aPdfFiles[$n], 4) & ".jpg"
    ConsoleWrite("$sBmpFile = " & $sBmpFile & @LF)

    ; Run Convert
    $RET = $oImgMgk.Convert("-thumbnail", "x100", $sPdfFile, $sBmpFile)
    ConsoleWrite("$RET = " & $RET & "; @error = " & @error & @LF & @LF)
Next

Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error 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   ;==>MyErrFunc

Works great with everything EXCEPT pdf files! :mellow:

My mistake was not having GhostScript installed. ImageMagick calls gswin32c.exe to handle PDFs (and PostScript, I guess) files. Now it works.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi again,

follow IE explorer embedded way, put some PDF in script folder :

#include <GUIConstants.au3>
#include <Misc.au3>

#include <GuiButton.au3>
#include <WindowsConstants.au3>

#include <String.au3>
#include <GuiListView.au3>
#include <array.au3>
#Include <Constants.au3>
#Include <GuiButton.au3>

#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#Include <File.au3>

#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <String.au3>

;//////////////////////////////////
;//     set variabili
;//////////////////////////////////
dim $my_selection = "", $my_old_selection = $my_selection, $sText= "", $my_selection_index


;//////////////////////////////////
;//     GUI
;//////////////////////////////////
$hGUI = GUICreate("SDII", 952, 700, 0, 0)

$Group1 = GUICtrlCreateGroup("Viewer", 264, 8, 681, 689)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$INVIA = GUICtrlCreateButton("INVIA", 8, 552, 249, 65, 0)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$ESCI = GUICtrlCreateButton("ESCI", 8, 622, 249, 65, 0)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("Combo1", 8, 401, 249, 21)
$Label1 = GUICtrlCreateLabel("Destinazione", 9, 364, 143, 33)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$INVIATI = GUICtrlCreateButton("Vedi già inviati", 8, 285, 249, 65, 0)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")

$Obj = ObjCreate("Shell.Explorer.1")
$browser = GUICtrlCreateObj($Obj, 275, 25, 665, 665)
GUICtrlSetResizing ( -1, $GUI_DOCKRIGHT )

$hCombo = GUICtrlCreateCombo("", 8, 20, 249, 273, BitOR($CBS_SIMPLE,$CBS_AUTOHSCROLL,$CBS_DISABLENOSCROLL,$WS_VSCROLL))

GUISetState(@SW_SHOW)


;//////////////////////////////////
;//     combo stuff
;//////////////////////////////////
;popolate combo
_GUICtrlComboBox_BeginUpdate($hCombo)
_GUICtrlComboBox_AddDir($hCombo, @ScriptDir & "\*.pdf")
_GUICtrlComboBox_EndUpdate($hCombo)

;select first element
_GUICtrlComboBox_SetCurSel($hCombo, $my_selection_index)
$my_selection = _GUICtrlComboBox_GetCurSel($hCombo)
_GUICtrlComboBox_GetLBText($hCombo, $my_selection, $sText)
$Obj.Navigate(@ScriptDir & '\' & $sText)

        
        
;//////////////////////////////////
;//     MAIN
;//////////////////////////////////
While 1
    $Msg = GUIGetMsg()
    Select

    Case $msg = $GUI_EVENT_CLOSE
        $question = MsgBox(4, "SDII", "Really quit ?")
        if $question = 6 then Exit ;if yes -> close program



    EndSelect

    
    ;obtain actual selection
    $my_selection = _GUICtrlComboBox_GetCurSel($hCombo)
    _GUICtrlComboBox_GetLBText($hCombo, $my_selection, $sText)


    ;if last selction is <> than old, user select another entry
    if $my_old_selection <> $my_selection Then

        $Obj.Navigate(@ScriptDir & '\' & $sText)
        GUISetState(@SW_SHOW)
        
        ;reset old & new position and wait for next selection
        $my_old_selection = $my_selection 
    EndIf
        
    sleep(10)

WEnd

Use IE explorer pdf viewer property, but strange things happen.

When i left main gui, application 'hang'. (in strange mode)

Anyone can explain me why ?

thank you,

m.

Edited by myspacee
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...