Skip to main content
Participating Frequently
February 14, 2024
Answered

Select Printer in InDesign

  • February 14, 2024
  • 3 replies
  • 1041 views

The documentation seems to imply I can change which printer I'm printing to by setting the `printer` property on the PrinterPreset or PrinterPresets object:

 

printer

Printer

Printer.POSTSCRIPT_FILE

String

read/write

The current printer. Can return: Printer enumerator or String.

 

I'm creating a new document and setting these properties at that time:

 

const doc = app.documents.add({
            name: `ipsum`,
            documentPreferences: {
                ....
            },
            viewPreferences: {
             ....
            },
            printPreferences: {
                printer: "lorem",
                ....
            }
});
 
This works for the other documented properties. However, InDesign seems to ignore the printer propterty. The printer is always the last used (selected by user) for that file or otherwise the application default. Not the one I'm specifying.
 
I confirmed that the printer I want exists using:
 
        const printers = app.activeDocument.printPreferences.printerList;
        console.log(printers);
 
I tried manually setting the printer name to the one I want:
 
printer: "RicohProd"
 
And instead it'll print to "BrotherFax", for instance.
 
Is there a way to do this? We're pulling the printer names from a database so I've only got the string to lookup by. If I have to figure out another way I will, but from experience with Acrobat scripting this feels like the way it should work.
 
Thank you.
This topic has been closed for replies.
Correct answer rob day

Hi @Brett35463984xsie , Try getting a printerPreset by name, or create a new preset, then set its printer property—here I’m using my function makePrintPreset("Name") to get the preset. Then set the job specific properties via printPreferences and print using the preset as the 2nd parameter:

 

var doc = app.activeDocument

//make or get a print preset named "MyEpson"
var pp = makePrintPreset("MyEpson");

//set the properties of the existing or new preset
pp.properties = {paperSize:"Letter",
                colorOutput: ColorOutputModes.COMPOSITE_RGB,
                printer: "EPSON Stylus"};

//set the job specific properties via printPreferences
doc.printPreferences.properties = {pageRange: PageRange.ALL_PAGES, allPrinterMarks:true}         

//Print with no dialog using the preset
doc.print(false, pp)


/**
* Make or get a print preset 
* @ param preset name 
* @ return the new or existing preset 
*/
function makePrintPreset(n){
    if (app.printerPresets.itemByName(n).isValid) {
        return app.printerPresets.itemByName(n);
    } else {
        return app.printerPresets.add({name:n});
    }
}

3 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
February 15, 2024

Hi @Brett35463984xsie , Try getting a printerPreset by name, or create a new preset, then set its printer property—here I’m using my function makePrintPreset("Name") to get the preset. Then set the job specific properties via printPreferences and print using the preset as the 2nd parameter:

 

var doc = app.activeDocument

//make or get a print preset named "MyEpson"
var pp = makePrintPreset("MyEpson");

//set the properties of the existing or new preset
pp.properties = {paperSize:"Letter",
                colorOutput: ColorOutputModes.COMPOSITE_RGB,
                printer: "EPSON Stylus"};

//set the job specific properties via printPreferences
doc.printPreferences.properties = {pageRange: PageRange.ALL_PAGES, allPrinterMarks:true}         

//Print with no dialog using the preset
doc.print(false, pp)


/**
* Make or get a print preset 
* @ param preset name 
* @ return the new or existing preset 
*/
function makePrintPreset(n){
    if (app.printerPresets.itemByName(n).isValid) {
        return app.printerPresets.itemByName(n);
    } else {
        return app.printerPresets.add({name:n});
    }
}
Participating Frequently
February 15, 2024

Thank you! This solution does work for me. I create a new preset and set the properties on that, and it prints to the correct printer.

leo.r
Community Expert
Community Expert
February 15, 2024

I'm not sure if that's the reason for your issue, but printer and printer preset are not document properties - they are app's properties. at least in AppleScript (I assume it should be the same in JS as the object hierarchy  should be the same - but that's just my assumption).

leo.r
Community Expert
Community Expert
February 15, 2024

...aslo, document's printPreferences property is read-only.

Participating Frequently
February 15, 2024

Not in UXP, and not when creating a new document, as far as I know

Participating Frequently
February 14, 2024

Correction:

 

the PrinterPreset or PrinterPresets PrintPreference object