Copy link to clipboard
Copied
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.POSTSCRIPT_FILE | read/write | The current printer. Can return: Printer enumerator or String. |
I'm creating a new document and setting these properties at that time:
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",
Copy link to clipboard
Copied
Correction:
the PrinterPreset or PrinterPresets PrintPreference object
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
...aslo, document's printPreferences property is read-only.
Copy link to clipboard
Copied
Not in UXP, and not when creating a new document, as far as I know
Copy link to clipboard
Copied
In JS this works for me, so maybe it’s a UXP problem? Did you try making the document then setting printPreferences after?
var doc = app.documents.add();
doc.printPreferences.properties = {pageRange: "1", allPrinterMarks:true, printer: "Brother HL-2170W series"}
The Print dialog before creating the new doc:
After:
Copy link to clipboard
Copied
Actually, I was wrong. (I was thinking of a different situation, not setting printing prefs in a new document).
I can confirm the same thing @rob day have posted, now in AppleScript:
tell application "Adobe InDesign 2024" to make new document with properties {print preferences:{printer:"PDF Printer"}}
This creates a new document with the specified printer selected.
Copy link to clipboard
Copied
Both of you seem right, it does work when I make a script but the same code in UXP doesn't seem to work. rob day's solution does work so I'm not going to stress about it! Thank you guys so much for your assistance so far
Copy link to clipboard
Copied
My recommendation is, not to print from InDesign. Export a PDF and print from Acrobat.
Copy link to clipboard
Copied
Can you tell me how to accomplish that via scripting in UXP?
Copy link to clipboard
Copied
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});
}
}
Copy link to clipboard
Copied
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.