Printing PDF does not seem to work.

Started by selwobevets, August 15, 2015, 11:40:21 AM

Previous topic - Next topic

selwobevets


I can not get this to work!   I keep getting an error message on the command avdoc.PrintPages(0,numpages-1,2,0,0).  The error is:  Not an OLE object-possible use of comma instead of period.  It does seem to read the PDF test file I created and the message shows 1 page.

Any ideas?



Automate Printing in Adobe Exchange
Keywords:     Automate Printing in Adobe   print a PDF file


Print a PDF file:   pdf_file = "C:\Temp\Test.pdf"

adobe = ObjectCreate("AcroExch.app") ; create an application object
pddoc = ObjectCreate("AcroExch.pddoc") ; create an application object
printdoc = ObjectCreate("AcroExch.avdoc") ; create an application object

pddoc.open(pdf_file)
printdoc.open(pdf_file, "")

numpages = pddoc.GetNumPages() ; Page count
Message("Number of pages", numpages)

avdoc = adobe.getActiveDoc

;PrintPages: Prints a specified range of pages displaying a print dialog box. PrintPages always uses the default printer setting.
; Syntax
;   VARIANT_BOOL PrintPages(long nFirstPage,long nLastPage,long nPSLevel, long bBinaryOk, long bShrinkToFit);
; Parameters
;  nFirstPage: The first page to be printed. The first page in a PDDoc object is page 0.
;  nLastPage: The last page to be printed.
;  nPSLevel: Valid values are 2 and 3. If 2, PostScriptÃ,® Level 2 operators are used. If 3, PostScript Language Level 3 operators are also used.
;  bBinaryOk: If a positive number, binary data can be included in the PostScript program. If 0, all data is encoded as 7-bit ASCII.
;  bShrinkToFit: If a positive number, the page is shrunk (if necessary) to fit within the imageable area of the printed page. If 0, it is not.
; Returns
;   0 if there were any exceptions while printing or if no document was open, -1 otherwise.

avdoc.PrintPages(0,numpages-1,2,0,0)


pddoc.close
adobe.CloseAllDocs()
adobe.exit ; exit the application

; Close object handles
pddoc = 0
printdoc = 0
adobe = 0


Article ID:   W15250




Home  TechHome  Tech Support Forum

td

Not particularly familiar with the Acrobat SDK but it would appear that your script has some flaws.  A few VBS examples found on the Internet all point to using the Open and GetPDDoc methods of the the  "AcroExch.AVDoc" object instead of attempting use the "AcroExch.App" object's getActiveDoc method.  This matches nicely with your WinBatch error which is likely the result of the  adobe.getActiveDoc line in your script returning a VT_NULL because the object doesn't have any awareness of the document you loaded in a different object. 

But again this observation is not based on first hand experience with the Acrobat SDK.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade