Add printer name in javascript code for check box page selection
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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?
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok! How do we do that? The only printer parameter code with a name specification I know is:
var pp = this.getPrintParams (); pp.firstPage = FIRST PAGE; pp.lastPage = LAST PAGE; pp.printerName = "NAME OF PRINTER"; this.print (pp);
But I don't know how to introduce it in the long code, where the FIRST PAGE and LAST PAGE are determined by the check boxes.
What would the code look like? Thanks!
Copy link to clipboard
Copied
Just like you did before:
var pp = this.getPrintParams();
pp.printerName = "Xerox VersaLink C405 (f1:da:8c)";
pp.firstPage = documentToPrint.startPage;
pp.lastPage = documentToPrint.endPage;
pp.interactive = pp.constants.interactionLevel.automatic;
this.print(pp);
Copy link to clipboard
Copied
Hi I have tried to simply replace the section this.print(showPrintDialog, documentToPrint.startPage, documentToPrint.endPage) by the var pp = this.getPrintParams() function like this:
var showPrintDialog = true;
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('Veuillez sélectionner au moins une station EBUS'); }
else { for ( var i = 0; i < documentsToPrint.length; i++){ var documentToPrint = documentsToPrint[i]; if(documentToPrint) {
var pp = this.getPrintParams();
pp.printerName = "Xerox VersaLink C405 (f1:da:8c)";
pp.firstPage = documentToPrint.startPage;
pp.lastPage = documentToPrint.endPage;
pp.interactive = pp.constants.interactionLevel.automatic;
this.print(pp); } } }
But it's not working. The action does not happen, it seem to not understand the function. What did I did wrong? Thanks!
Copy link to clipboard
Copied
Nothing happens at all? No error message, nothing?
Can you share the file in question, please?

