JohnBailey Posted September 20, 2007 Author Share Posted September 20, 2007 Example: How to work with AcroJS if it should work with Acrobat and/or Reader only. expandcollapse popup;=============================================================================== ; Example: Execute Acro JS via FDF file ; Description: Write bookmarks of a PDF to a textfile ; Works with Acrobat and Reader ;=============================================================================== #include <GUIConstants.au3> ; Setting variables Global $sFilename = "C:\Temp.pdf" Global $sDir = "C:\" ; Creating GUI and controls GUICreate("Gather Bookmarks from PDF to File", 385, 140, @DesktopWidth/2 - 192, @DesktopHeight/2 - 235, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateGroup("", 5, 1, 375, 40) GUICtrlCreateGroup("", 5, 50, 375, 80) $hFile = GUICtrlCreateEdit($sFilename, 12, 15, 325, 16, $ES_OEMCONVERT , $WS_EX_STATICEDGE) GUICtrlSetCursor(-1, 2) GUICtrlSetState(-1, $GUI_ACCEPTFILES) GUICtrlSetTip(-1, "You can drop files from shell here...") $hFileSel = GUICtrlCreateButton("...", 345, 14, 26, 18) GUICtrlCreateLabel ("This App reads bookmarks from Acrobat or Reader to a file.", 10, 60, 300) $BMRead = GUICtrlCreateButton("ReFOB Gather Bookmarks to File", 10, 90, 170, 24,$BS_FLAT) $Quit = GUICtrlCreateButton("Quit", 185, 90, 170, 24, $BS_FLAT) GUISetState() While 1 $iMsg = GUIGetMsg() ; Code below will check if the file is dropped (or selected) $sPDF = GUICtrlRead($hFile) ; Main "Select" statement that handles other events Select Case $iMsg = $hFileSel $sTmpFile = FileOpenDialog("Select file:", $sDir, "PDF Files (*.PDF)") If @error Then ContinueLoop GUICtrlSetData($hFile, $sTmpFile) $sDir = stringMid($sTmpFile,1,stringInStr($sTmpFile,"\",0,-1)) $sPDF = $sTmpFile Case $iMsg = $BMRead WriteFDF() Case $iMsg = $Quit Exit Case $iMsg = $GUI_EVENT_CLOSE Exit EndSelect Wend FUNC WriteFDF() If FileExists($sPDF) Then $sX = StringReplace($sPDF,"\","/") $sX = StringReplace($sX,":","") $sPdfNM = "/" &$sX $FdfNM = FileOpen( "C:\Temp.FDF",2) $Ex = "%FDF-1.2 %%---DEMO EXECUTE Javascript VIA FDF---%%" &@CRLF _ &"1 0 obj << /FDF << /F (" &$sPdfNM &") /Javascript << /Before 2 0 R >> >> >> endobj"&@CRLF _ &"2 0 obj << >> stream" &@CRLF _ &"" &@CRLF _ & " var f=""ReFOB Reader Extension""+""\n"";"&@CRLF _ & " f +=""List of Bookmarks""+""\n"";"&@CRLF _ & " function DumpBookmark(bm, nLevel)"&@CRLF _ & " {"&@CRLF _ & " var s = """";"&@CRLF _ & " for (var i = 0; i < nLevel; i++)"&@CRLF _ & " s += "" "";"&@CRLF _ & " f += (s + bm.name + ""\n"");"&@CRLF _ & " if (bm.children != null)"&@CRLF _ & " for (var i = 0; i < bm.children.length; i++)"&@CRLF _ & " DumpBookmark(bm.children[i], nLevel + 1);"&@CRLF _ & " }"&@CRLF _ & " DumpBookmark(this.bookmarkRoot, 0);"&@CRLF _ & " app.alert(f);"&@CRLF _ &"" &@CRLF _ & "endstream"&@CRLF _ & "endobj"&@CRLF _ & "trailer << /Root 1 0 R >> %%EOF" FileWrite($FdfNM,$Ex) FileClose($FdfNM) ; //Run FDF Opt("WinTitleMatchMode", 2);2=Substrg. RunWait(@ComSpec & " /c " & 'start c:\Temp.fdf' , "", @SW_HIDE) Do $OK = WinWaitActive ( "", "ReFOB Reader Extension",3) if $OK=0 then $iMsg = GUIGetMsg() if $iMsg = $GUI_EVENT_CLOSE then exit endif until $OK=1 WinMove ( "", "ReFOB Reader Extension", 800, 760 ) $var = WinGetText ( "","ReFOB Reader Extension") ;; WinClose( "", "ReFOB Reader Extension");; don't work since v7 send("{ENTER}") FileDelete("C:\temp.fdf") $var = stringleft($var,stringlen($var)-6) $var = StringReplace($var,"ReFOB Reader Extension", "File: "&$sPDF) ClipPut($var) $bak = ClipGet() $TxtFNM = FileOpen( "C:\Temp.txt",2) FileWrite($TxtFNM,$bak) FileClose($TxtFNM) RunWait(@ComSpec & " /c " & 'start c:\Temp.txt' , "", @SW_HIDE) Else MsgBox(4096, "Gather Bookmarks", "Ups, PDF-File don't exists") EndIf EndFunc The AcroJS code is direct from the help file, only prepared as textvariable. If you have much time you may translate it to JSO or IAC, but then it doesn't work with Reader only. HTH, Reinhard That is really RAD! I see how expansive this can be With that you could then even use PDBookmark obj... A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted September 20, 2007 Author Share Posted September 20, 2007 1) If the Reader is open you get an error because Reader don't work with AcroExch. With Reader you can execute only some few DDE functions2) That someone has Reader and Acrobat open may be very seldom. I like to read the helpfiles in Reader and to work with Acrobat.Best regards, Reinhardgotcha. What if though Acrobat.exe is open first and then the script tries to reexecute that exe? A decision is a powerful thing Link to comment Share on other sites More sharing options...
ReFran Posted September 20, 2007 Share Posted September 20, 2007 gotcha. What if though Acrobat.exe is open first and then the script tries to reexecute that exe?Should work. Link to comment Share on other sites More sharing options...
JohnBailey Posted September 20, 2007 Author Share Posted September 20, 2007 (edited) Example: How to work with Acrobat if Reader is running. ;; Start Acrobat also if Reader is open $fileIn = "C:\Test.pdf" ;; Start Acrobat (Check if Reader is open) if Processexists("AcroRd32.exe") then $AcPath = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.EXE","") $AcVersion = FileGetVersion ( $Acpath ,"ProductVersion") ShellExecute($AcPath,"/n") sleep(3000) endif $App = ObjCreate("AcroExch.App") $App.Show $AVDoc = ObjCreate("AcroExch.AVDoc") $AVDoc.Open($fileIn,"") $PDDoc = $AVDoc.GetPDDoc $JSO = $PDDoc.GetJSObject $JSO.app.alert("Hallo. The file is open press Ok to go on") Is there a way not to use the sleep? I'm doing the following, but I don't like the sleep function expandcollapse popup=============================================================================== ; ; Function Name: _AcrobatIC_Create() ; Description: Create Acrobat Window ; Parameter(s): ; $aic_Show - boolean - Optional: specifies whether or not the Acrobat Window is visible ; True = (Default) Show window ; False = Leave window hiden ; $useSpecifiedLocation - string - Optional: specifies whether to use the RegRead or to use a specified location not with the RegRead ; '' = (Default) RegRead is used ; ; Requirement(s): Full Version of Acrobat version 6 or greater ; Return Value(s): On Success - Returns the AcroExch.App Object Ref ; On Failure - Returns 0 and sets @ERROR ; @ERROR - 0 = Acrobat Reg could not be found ; - 1 = Specified location does not exist ; - 2 = Object not created ; - 3 = Acrobat.exe did not execute ; @Extended - ; CallTip: ; Author(s): John Bailey, ReFran ; ;=============================================================================== Func _AcrobatIC_Create($aic_Show=True,$useSpecifiedLocation='') ; Start Acrobat (Check if Reader is open);ReFran (http://www.autoitscript.com/forum/index.php?showtopic=53512&view=findpost&p=406154) if Processexists("AcroRd32.exe") then If $useSpecifiedLocation = '' Then Local $aic_AcPath = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.EXE","") If @error Then SetError(0,@extended,0) Local $aic_AcVersion = FileGetVersion ( $aic_Acpath ,"ProductVersion") Else Local $aic_AcPath = $useSpecifiedLocation If FileExists($aic_AcPath) = 0 Then SetError(1,'',0) EndIf ShellExecute($aic_AcPath,"/n") sleep(3000) endif $aic_obj = ObjCreate("AcroExch.App") If not IsObj($aic_obj) then SetError(2,'',0) EndIf If Not Processexists("Acrobat.exe") Then SetError(3,'',0) EndIf If $aic_Show Then $aic_obj.Show Return $aic_obj EndFunc Edited September 20, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
ReFran Posted September 20, 2007 Share Posted September 20, 2007 Is there a way not to use the sleep? I'm doing the following, but I don't like the sleep function [\quuote] $OK = Processwait("Acrobat.exe",5] if $OK=0 then msgbox(0,"","Ups, coudn't start Acrobat!") Exit endif Link to comment Share on other sites More sharing options...
JohnBailey Posted September 20, 2007 Author Share Posted September 20, 2007 $OK = Processwait("Acrobat.exe",5] if $OK=0 then msgbox(0,"","Ups, coudn't start Acrobat!") Exit endifhaha good idea! A decision is a powerful thing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now