• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Select Printer in InDesign

Community Beginner ,
Feb 14, 2024 Feb 14, 2024

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

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.
TOPICS
UXP Scripting

Views

252

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 15, 2024 Feb 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",
    
...

Votes

Translate

Translate
Community Beginner ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

Correction:

 

the PrinterPreset or PrinterPresets PrintPreference object

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2024 Feb 14, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2024 Feb 15, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2024 Feb 15, 2024

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:

 

Screen Shot 20.png

 

After:

Screen Shot 21.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2024 Feb 15, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2024 Feb 15, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2024 Feb 15, 2024

Copy link to clipboard

Copied

My recommendation is, not to print from InDesign. Export a PDF and print from Acrobat. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2024 Feb 15, 2024

Copy link to clipboard

Copied

Can you tell me how to accomplish that via scripting in UXP?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2024 Feb 15, 2024

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});
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2024 Feb 15, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines