Jump to content
Sign in to follow this  
JohnBailey

Interapplication Communication API Reference - problem (print)

Recommended Posts

JohnBailey

Does anyone know why the below script won't 1.) reopen previously opened and 2.) won't print.

Note: the ProcessClose's are there for testing

http://www.adobe.com/devnet/acrobat/pdfs/i...i_reference.pdf

Local $printFile = FileOpenDialog('Select a PDF',@MyDocumentsDir,'PDF (*.pdf)')
Local $app = ObjCreate("AcroExch.App")
Local $avdoc = ObjCreate("AcroExch.AVDoc")
$avdoc.open($printFile, "Temp Title")
if IsObj($app) Then
    ConsoleWrite("OK")
;Local $pdDoc = $avDoc.GetPDDoc()
;$pdDoc.Print()
Else
    ConsoleWrite("!!NOPE!!")
    Exit
EndIf
ProcessClose("Acrobat.exe")
ProcessClose("AcrobatInfo.exe")
ProcessClose("Adobelmsvc.exe")
;if $avdoc.IsValid = True Then
;Local $pddoc = $avdoc.GetPDDoc()
;$pddoc.Print()
;EndIf

;Local $pdfDist = New PdfDistiller
;pdfDist.FileToPDF "c:\filename.ps", "c:\filename.pdf", "

A decision is a powerful thing

Share this post


Link to post
Share on other sites
evilertoaster

;$pdDoc.Print()

1. Make sure it's not commented out :)

2. The PDDoc object (as returned by the .GetPDDoc() method) does not contain a method called 'Print'. Look maybe at the AxAcroPDFLib.AxAcroPDF object which has a .Print or the origional .AVdoc object you used which has a .PrintPages method.

Share this post


Link to post
Share on other sites
JohnBailey

1. Make sure it's not commented out :)

2. The PDDoc object (as returned by the .GetPDDoc() method) does not contain a method called 'Print'. Look maybe at the AxAcroPDFLib.AxAcroPDF object which has a .Print or the origional .AVdoc object you used which has a .PrintPages method.

1. HAHA yeah that was very much a C&P issue. I posted a bit of a huge file i was working on.

2. where do I find the list of "methods"?! :) How'd you know that?!


A decision is a powerful thing

Share this post


Link to post
Share on other sites
evilertoaster

where do I find the list of "methods"?! :) How'd you know that?!

From the referance file you posted in your original post.

Share this post


Link to post
Share on other sites
JohnBailey

From the referance file you posted in your original post.

:) :"> thanks! I'm actually make much progress now!!!


A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

EDIT: Nevermind about the below. I'm just going to do it a better way anyway.

This should be so basic, but I don't know how to correct the below script.

The problem is that the Array cannot be used in the place of a variable (I know my sentence may not make sense, but the error code at the bottom should help if the script itself is not obvious).

;===============================================================================
;
; Function Name:    _AcrobatIC_OpenFileFresh()
; Description:    Open an Acrobat File
; Parameter(s):  $aic_FiletoOpen    - specifies what file to open
;                   $aic_Show       - Optional: specifies whether or not the Acrobat Window is visible
;                                       True  = (Default) Show window
;                                       False = Leave window hiden
;
; Requirement(s):   
; Return Value(s):  On Success  - Returns an array with 
;                                   the AcroExch.App Object Ref ([0])
;                                   the AcroExch.PDDoc Object Ref ([1])
;                                   the AcroExch.PDDoc Object Ref ([2])
;                  On Failure   - Returns 0 and sets @ERROR
;                   @ERROR      - 0 
;                   @Extended   - 
; CallTip:
; Author(s):        John Bailey
;
;===============================================================================
Func _AcrobatIC_OpenFileFresh($aic_FiletoOpen,$aic_Show=True)
    Local $aic_refArray[2]
    
    $aic_refArray[0] = ObjCreate("AcroExch.App")
    $aic_refArray[1] = ObjCreate("AcroExch.AVDoc")
    If not IsObj($aic_refArray[1]) then 
        SetError(0,'',0)
    EndIf
    $aic_refArray[1].Open($aic_FiletoOpen,$aic_FiletoOpen)
    $aic_refArray[2] = $aic_refArray[1].GetPDDoc()
    If $aic_Show Then
        $aic_refArray[0].Show
    EndIf
    
    Return $aic_refArray
EndFunc

ERROR

Adobe Interapplication Communication.au3 (116) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
$aic_refArray[2] = $aic_refArray[1].GetPDDoc() 
^ ERROR
Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites
ReFran

Have a look at AvDocOpen.

HTH, Reinhard

$fileIn = "C:\Test.pdf"         ;; state the full path of the file to open
$FileOut = "C:\Test3.pdf"       ;; state the full path for the file to save

$App = ObjCreate("AcroExch.App")           ;; start Adobe Acrobat
$App.Show                                                    ;; show Acrobat

$AVDoc = ObjCreate("AcroExch.AVDoc")  ;; connect to  Ac Viewer          
$AVDoc.Open($fileIn,"")                       ;; Open a file into viewer

$PDDoc = $AVDoc.GetPDDoc                  ;; Get the Doc opened in the viewer
$JSO = $PDDoc.GetJSObject                   ;; Connect to Acrobat JS
$JSO.app.alert("Hallo. The file is open press Ok and I'll save it") ;; Display a MsgBox
$PDDoc.Save(3,$fileOut)                         ;; SaveAs

$App.CloseAllDocs                                     ;; close all docs

Share this post


Link to post
Share on other sites
JohnBailey

Have a look at AvDocOpen.

HTH, Reinhard

$fileIn = "C:\Test.pdf"     ;; state the full path of the file to open
$FileOut = "C:\Test3.pdf"   ;; state the full path for the file to save

$App = ObjCreate("AcroExch.App")          ;; start Adobe Acrobat
$App.Show                                                   ;; show Acrobat

$AVDoc = ObjCreate("AcroExch.AVDoc") ;; connect to  Ac Viewer           
$AVDoc.Open($fileIn,"")                      ;; Open a file into viewer

$PDDoc = $AVDoc.GetPDDoc                 ;; Get the Doc opened in the viewer
$JSO = $PDDoc.GetJSObject               ;; Connect to Acrobat JS
$JSO.app.alert("Hallo. The file is open press Ok and I'll save it");; Display a MsgBox
$PDDoc.Save(3,$fileOut)                     ;; SaveAs

$App.CloseAllDocs                                    ;; close all docs
:)

That is indeed what I was looking for. I got a UDF going yesterday. It's fresh, so PLEASE feel free to add on or correct it

http://www.autoitscript.com/forum/index.php?showtopic=53572


A decision is a powerful thing

Share this post


Link to post
Share on other sites
ReFran

:)

That is indeed what I was looking for. I got a UDF going yesterday. It's fresh, so PLEASE feel free to add on or correct it

http://www.autoitscript.com/forum/index.php?showtopic=53572

I think to use the Acobat Object Shema (LDispatch, works with this but not with that version) is hard enough.

So I don't want to complicate it with UDF's from third :-).

A GUI may be more helpfull - or only same example scripts in AutoIT.

Best regards, Reinhard

Share this post


Link to post
Share on other sites
JohnBailey

I think to use the Acobat Object Shema (LDispatch, works with this but not with that version) is hard enough.

So I don't want to complicate it with UDF's from third :-).

A GUI may be more helpfull - or only same example scripts in AutoIT.

Best regards, Reinhard

I don't really understand what you said :) It seems really important


A decision is a powerful thing

Share this post


Link to post
Share on other sites
ReFran

I don't really understand what you said :) It seems really important

I don't want to frustate you. In general is a good Idea!

But to write UDF for Acrobat may be very hard. There are differences from version to version

and also the installation are important.

Some Exampels:

If you have Acrobat and Reader installed and Reader is open my given example and your UDFs wouldn't work, because the Reader is already open. (a special Adobe thinking: The opened viewer taksover).

So you would have to check first, if Reader is running, if yes then start acrobat in a new process (....acrobate.exe /n) and then execute the script.

MenuitemInsert/Menuitemexecute ... doesn't work since version 8 (at least not direct).

So I think spending "...... same example scripts in AutoIT" for working with Acrobat SDK/IAC would be very helpfull.

By the way, you know that you can use most AcroJS example scripts? That helps a lot.

Good luck, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites
JohnBailey

I don't want to frustate you. In general is a good Idea!

But to write UDF for Acrobat may be very hard. There are differences from version to version

and also the installation are important.

I just want a basic udf that others can build off of. Maybe calling it a udf is misleading. I don't know what to call it. I just want to share what I'm using.

Not frustrated. Thank you for expressing that though. I am concerned with making this helpful for others as well. Your ideas and concerns are REALLY important to me, even if you're telling me it's stupid for such-or-such reason. I may completely be missing something or be screwing something up.

Some Exampels:

If you have Acrobat and Reader installed and Reader is open my given example and your UDFs wouldn't work, because the Reader is already open. (a special Adobe thinking: The opened viewer taksover).

So you would have to check first, if Reader is running, if yes then start acrobat in a new process (....acrobate.exe /n) and then execute the script.

Sounds like a fabulous idea! I'm not sure how to do that though.

MenuitemInsert/Menuitemexecute ... doesn't work since version 8 (at least not direct).

From what I can tell you must use the JS.Console to execute those OR something like that.

So I think spending "...... same example scripts in AutoIT" for working with Acrobat SDK/IAC would be very helpfull.

? what does that mean?

By the way, you know that you can use most AcroJS example scripts? That helps a lot.

yeah they do I'm adding a function for getting the JSObj.

A decision is a powerful thing

Share this post


Link to post
Share on other sites
ReFran

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")

Share this post


Link to post
Share on other sites
ReFran

Example: How to work with JSO or Execute AcroJS:

$fileIn = "C:\Test.pdf" 

$App = ObjCreate("AcroExch.App") 
;$App.Show ;; comment out to work hidden                      
$AVDoc = ObjCreate("AcroExch.AVDoc") 
$AForm = ObjCreate("AFormAut.App") ;from AFormAPI

If $AVDoc.Open($FileIn,"") Then 
   $PDDoc = $AVDoc.GetPDDoc() 
  ;; pure JSO Solution
   $JSO = $PDDoc.GetJSObject 
   $f = $jso.path
   $p = $jso.numPages
   msgbox(0,"Info via JS0 ","File: " &$f &@Cr &"Pages: "&$p)
  ;; Execute AcroJS
   $JSO = $PDDoc.GetJSObject;; needed to get back the variables
   $p = $AForm.Fields.ExecuteThisJavascript('var p = this.numPages; var f = this.path;')
   msgBox(0,"Info from execute Acro JS", "File: " & $jso.f &@Cr &"Pages: " &$jso.p)
endif

That is a simple example. The next example show you how flexible you can work AcroJS.

So I prefer, to use Acro-JS, at least if an example is given in AcroJS helpfile.

Then I can use it: direct in Acrobat or via IAC and partly also with Reader

Share this post


Link to post
Share on other sites
ReFran

Example: How to work with AcroJS if it should work with Acrobat and/or Reader only.

;===============================================================================
; 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

Share this post


Link to post
Share on other sites
JohnBailey

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")

For starters, thank you for all the example scripts! I want to integrate those into my funcs :) Also, I'm not totally understanding how Acrobat AcroExch works.

With those said, let me get this straight. If the reader is open creating an obj of AcroExch.App, will use the Reader. However, if you open Acrobat.exe (the full version), then the obj is going to use the full version. Is that correct?

Why not just close AcroRd32.exe? Is it because someone may still want that open?

I'm not a fan of sleeps. Is there a different way that can be achieved?


A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

Example: How to work with JSO or Execute AcroJS:

$fileIn = "C:\Test.pdf" 

$App = ObjCreate("AcroExch.App") 
;$App.Show;; comment out to work hidden                   
$AVDoc = ObjCreate("AcroExch.AVDoc") 
$AForm = ObjCreate("AFormAut.App");from AFormAPI

If $AVDoc.Open($FileIn,"") Then 
   $PDDoc = $AVDoc.GetPDDoc() 
 ;; pure JSO Solution
   $JSO = $PDDoc.GetJSObject 
   $f = $jso.path
   $p = $jso.numPages
   msgbox(0,"Info via JS0 ","File: " &$f &@Cr &"Pages: "&$p)
 ;; Execute AcroJS
   $JSO = $PDDoc.GetJSObject;; needed to get back the variables
   $p = $AForm.Fields.ExecuteThisJavascript('var p = this.numPages; var f = this.path;')
   msgBox(0,"Info from execute Acro JS", "File: " & $jso.f &@Cr &"Pages: " &$jso.p)
endif

That is a simple example. The next example show you how flexible you can work AcroJS.

So I prefer, to use Acro-JS, at least if an example is given in AcroJS helpfile.

Then I can use it: direct in Acrobat or via IAC and partly also with Reader

That's pretty rad that Acro-JS can do the same thing as PDDoc and AVDoc functions can.

The AcroJS file you're referring to is one of these?----

http://www.planetpdf.com/codecuts/pdfs/tutorial/AcroJS.pdf

http://www.planetpdf.com/planetpdf/pdfs/jkingformsano.pdf

http://partners.adobe.com/public/developer...ript/AcroJS.pdf

http://www.acrotips.com/pdf/articles/AcroT...0Javascript.pdf

http://www.startaid.com/comment/538470/Acr...df-Objekt).html


A decision is a powerful thing

Share this post


Link to post
Share on other sites
ReFran

1) With those said, let me get this straight. If the reader is open creating an obj of AcroExch.App, will use the Reader. However, if you open Acrobat.exe (the full version), then the obj is going to use the full version. Is that correct?

2)Why not just close AcroRd32.exe? Is it because someone may still want that open?

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 functions

2) 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, 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  

×