Skip to main content
Participant
June 4, 2023
Question

Add printer name in javascript code for check box page selection

  • June 4, 2023
  • 1 reply
  • 1397 views

Hi! I have a print button in a form that prints specific pages based on the check boxes that are checked on page 1 (most often more than 1 page). The page selection process works well, but I need to send the selected pages to a specific printer. I guess I would need to specify the printer name in a script such as:

var pp = this.getPrintParams ();  pp.printerName = "Xerox VersaLink C405 (f1:da:8c)"; this.print (pp);

However, I cannot find the place in my page-selection process code where I can implement this variable. I need to keep the print dialog box as "false" (not showing up), as there might be multiple non-continguous pages printed with 1 click of the print button, and I don't want the print dialog box to open up before each page.

Here is my script for the print button currently:

var showPrintDialog = false; var checkBoxToDocInfo = { cb1: { startPage: 1, endPage: 1 }, cb2: { startPage: 2, endPage: 2 }, cb3: { startPage: 3, endPage: 3 }, cb4: { startPage: 4, endPage: 4 }, cb5: { startPage: 5, endPage: 5 }, cb6: { startPage: 6, endPage: 6 }, cb7: { startPage: 7, endPage: 7 }, cb8: { startPage: 8, endPage: 8 }, cb9: { startPage: 9, endPage: 9 }, cb10: { startPage: 10, endPage: 10 }, cb11: { startPage: 11, endPage: 11 }, cb12: { startPage: 12, endPage: 12 }, cb13: { startPage: 13, endPage: 13 }, cb14: { startPage: 14, endPage: 14 }, cb15: { startPage: 15, endPage: 15 }, cb16: { startPage: 16, endPage: 16 }, cb17: { startPage: 17, endPage: 17 }, cb18: { startPage: 18, endPage: 18 }, cb19: { startPage: 19, endPage: 21 }, } var documentsToPrint = []; for(var i = 1; i<=19; i++) { var cbName = "cb" + i; if (this.getField(cbName).value == "Yes") { var docInfo = checkBoxToDocInfo[cbName]; if(docInfo) { documentsToPrint.push(docInfo); } } } if(documentsToPrint.length <= 0) { app.alert('Please select at least one page'); } else { for ( var i = 0; i < documentsToPrint.length; i++){ var documentToPrint = documentsToPrint[i]; if(documentToPrint) { this.print(showPrintDialog, documentToPrint.startPage, documentToPrint.endPage); } } }

Thanks!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 4, 2023

You have the right code for printing in the start of your message. Why aren't you using that in the later part?

To hide the print dialog add this line before calling the print method:

pp.interactive = pp.constants.interactionLevel.automatic;

Participant
June 5, 2023

Thanks! I already have coded the print dialog box to not show right at the begging of my copied code.

What do you mean by the "later part"? Where exactly would you introduce the printer name specification and how?

quote

You have the right code for printing in the start of your message. Why aren't you using that in the later part?

To hide the print dialog add this line before calling the print method:

pp.interactive = pp.constants.interactionLevel.automatic;


By @try67

 

try67
Community Expert
Community Expert
June 5, 2023

By last part I meant this:

this.print(showPrintDialog, documentToPrint.startPage, documentToPrint.endPage);

This needs to be replaced with the print command that uses the PrintParams object.