Setting PrinterName doesn't really preselect the printer in the print dialog box

Community Beginner ,
Dec 17, 2017

Copy link to clipboard

Copied

I have 2 printers. One is specially bought for shipping labels.

All my shipping labels are generated pdf files with smaller dimensions (153,8 x 106,2 mm, let's say A6 format).

As I use the other printer on the same machine (iMac) for all "normal" A4 pdf documents, I always have to be careful not to waste shipping labels, using Acrobat Reader DC taking into account the last chosen printer will be preselected in the print dialog box. This, of course, is the normal behavior of Acrobat Reader.

My Acrobat Reader DC:

Architecture: x86_64

Build: 18.9.20050.254034

AGM: 4.30.72

CoolType: 5.14.5

JP2K: 1.2.2.39492

My iMac:

OS X El Capitan version 10.11.6

The next script normally should launch the print dialog box with the best printer preselected (in function of the paper size).

  • the printers on my iMac are known as "DYMO LabelWriter 4XL" (for the shipping labels) and "Brother HL-L2360D series" (for A4 documents).
  • from the moment the document has smaller dimensions (< 160 x 108 mm), the Dymo label printer must be chosen.
  • In the acrobat Reader DC program I enabled "Acrobat JavaScript", "Enable menu items JavaScript execution privileges" and "Show console on errors and messages".
  • the app.alert at the end is an extra feedback during the tetst and shows me the name of the chosen printer just before launching the print dialog box.

// start script

var defaultPrinter = (new String("DYMO LabelWriter 4XL"));

var largeFormatPrinter = (new String("Brother HL-L2360D series"));

var pageBox = this.getPageBox();

var pageWidth = pageBox[2]/2.83;

var pageHeight = pageBox[1]/2.83;

var selectedPrinterName;

if (pageWidth<160 && pageHeight<108) {

  selectedPrinterName = ""+defaultPrinter;

}

else {

  selectedPrinterName = ""+largeFormatPrinter;

}

var pp = this.getPrintParams();

pp.printerName = selectedPrinterName;

app.alert("The chosen printer is " + pp.printerName, 3);

this.print(pp);

// end script

Problem: Even if the correct printer is displayed in the alert (defined by the page dimensions), the preselected printer in the print dialog box is not always the right printer. It still will be the last used one: the normal behavior of Acrobat Reader. Somebody told me it was really working on his Windows machine. Is there something I'll have to configure in the Acrobat Reader program preferences or something else I'll have to take into account on a iMac machine?

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

160

Likes

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

Setting PrinterName doesn't really preselect the printer in the print dialog box

Community Beginner ,
Dec 17, 2017

Copy link to clipboard

Copied

I have 2 printers. One is specially bought for shipping labels.

All my shipping labels are generated pdf files with smaller dimensions (153,8 x 106,2 mm, let's say A6 format).

As I use the other printer on the same machine (iMac) for all "normal" A4 pdf documents, I always have to be careful not to waste shipping labels, using Acrobat Reader DC taking into account the last chosen printer will be preselected in the print dialog box. This, of course, is the normal behavior of Acrobat Reader.

My Acrobat Reader DC:

Architecture: x86_64

Build: 18.9.20050.254034

AGM: 4.30.72

CoolType: 5.14.5

JP2K: 1.2.2.39492

My iMac:

OS X El Capitan version 10.11.6

The next script normally should launch the print dialog box with the best printer preselected (in function of the paper size).

  • the printers on my iMac are known as "DYMO LabelWriter 4XL" (for the shipping labels) and "Brother HL-L2360D series" (for A4 documents).
  • from the moment the document has smaller dimensions (< 160 x 108 mm), the Dymo label printer must be chosen.
  • In the acrobat Reader DC program I enabled "Acrobat JavaScript", "Enable menu items JavaScript execution privileges" and "Show console on errors and messages".
  • the app.alert at the end is an extra feedback during the tetst and shows me the name of the chosen printer just before launching the print dialog box.

// start script

var defaultPrinter = (new String("DYMO LabelWriter 4XL"));

var largeFormatPrinter = (new String("Brother HL-L2360D series"));

var pageBox = this.getPageBox();

var pageWidth = pageBox[2]/2.83;

var pageHeight = pageBox[1]/2.83;

var selectedPrinterName;

if (pageWidth<160 && pageHeight<108) {

  selectedPrinterName = ""+defaultPrinter;

}

else {

  selectedPrinterName = ""+largeFormatPrinter;

}

var pp = this.getPrintParams();

pp.printerName = selectedPrinterName;

app.alert("The chosen printer is " + pp.printerName, 3);

this.print(pp);

// end script

Problem: Even if the correct printer is displayed in the alert (defined by the page dimensions), the preselected printer in the print dialog box is not always the right printer. It still will be the last used one: the normal behavior of Acrobat Reader. Somebody told me it was really working on his Windows machine. Is there something I'll have to configure in the Acrobat Reader program preferences or something else I'll have to take into account on a iMac machine?

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

161

Likes

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
Dec 17, 2017 0
Adobe Community Professional ,
Dec 17, 2017

Copy link to clipboard

Copied

The printer UI is not linked to the JavaScript objects in a direct manner. One can set the printer name in the Print Params object but then one needs to the document object print method to print using the print params

Likes

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
Reply
Loading...
Dec 17, 2017 0
Community Beginner ,
Dec 17, 2017

Copy link to clipboard

Copied

Thats exactly what I'm doing, right?

I call the function by a self created menu:

app.addMenuItem({ cName: "MyFilename", cUser: "Print by page size", cParent: "File", nPos: "Print", cExec: "myOwnFunction()", cEnable: "event.rc = (event.target != null);"});

Likes

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
Reply
Loading...
Dec 17, 2017 0
Community Beginner ,
Dec 25, 2017

Copy link to clipboard

Copied

Hi Gkaiseril,

isn’t the call of the last function in this code this.print(pp) doing this?

Likes

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
Reply
Loading...
Dec 25, 2017 0