CHAPTER 3: Documents Printing a Document 41
Printing a Document
The following script prints the active document using the current print preferences. (For the complete
script, see PrintDocument.)
app.activeDocument.print();
Printing using page ranges
To specify a page range to print, set the pageRange property of the document’s print preferences
object before printing, as shown in the following script fragment (from the PrintPageRange tutorial script):
//Prints a page range from the active document.
//Assumes that you have a document open, that it contains a page named "22".
//The page range can be either PageRange.allPages or a page range string.
//A page number entered in the page range must correspond to a page
//name in the document (i.e., not the page index). If the page name is
//not found, InDesign will display an error message.
app.activeDocument.printPreferences.pageRange = "22"
app.activeDocument.print(false);
Setting print preferences
The print preferences object contains properties corresponding to the options in the panels of the Print
dialog. This following script shows how to set print preferences using scripting. (For the complete script,
see PrintPreferences.)
//PrintPreferences.jsx
//An InDesign CS5 JavaScript
//Sets the print preferences of the active document.
with(app.activeDocument.printPreferences){
//Properties corresponding to the controls in the General panel
//of the Print dialog box. activePrinterPreset is ignored in this
//example--we'll set our own print preferences. printer can be
//either a string (the name of the printer) or Printer.postscriptFile.
printer = Printer.postscriptFile;
//Here's an example of setting the printer to a specific printer.
//printer = "AGFA-SelectSet 5000SF v2013.108";
//If the printer property is the name of a printer, then the ppd property
//is locked (and will return an error if you try to set it).
//ppd = "AGFA-SelectSet5000SF";
//If the printer property is set to Printer.postscript file, the copies
//property is unavailable. Attempting to set it will generate an error.
//copies = 1;
//If the printer property is set to Printer.postscript file, or if the
//selected printer does not support collation, then the collating
//property is unavailable. Attempting to set it will generate an error.
//collating = false;
reverseOrder = false;
//pageRange can be either PageRange.allPages or a page range string.
pageRange = PageRange.allPages;
printSpreads = false;
printMasterPages = false;
//If the printer property is set to Printer.postScript file, then
//the printFile property contains the file path to the output file.
//printFile = "/c/test.ps";