Copy link to clipboard
Copied
I am trying to print multiple pages per sheet (1x3) print to file using javascript. I want it to print in silent mode. I have the output file name specified in the code. But it it showing 'save as' dialog box before printing. Once file name is supplied, it prints as specified.
I don't want the 'save as' dialog box. I want it to be silent. What change do I need to make in the code here?
var re = /\.pdf$/i; //regex to to acquire the base name of file
var baseFileName = this.documentFileName.replace(re, ""); //***without base file name, all fails
var fName = baseFileName + " print test" + ".prn"
pp = this.getPrintParams();
pp.bUI = false //non-interactive printing
pp.bSilent = true //non-interactive printing
pp.bShrinkToFit = false
pp.interactive = pp.constants.interactionLevel.silent; //non-interactive printing
pp.printerName = "Adobe PDF"; //print to file
pp.fileName = fName; //"/c/print/myDoc.prn";
pp.pageHandling = pp.constants.handling.nUp; //setting up multiple pages per sheet
pp.nUpPageOrders = pp.constants.nUpPageOrders.Horizontal; //Vertical
// pp.firstPage = 0; //specify start page;0-indexed
// pp.lastPage = 4; //specify end page;0-indexed
pp.nUpNumPagesH = 1;
pp.nUpNumPagesV = 3;
pp.nUpPageBorder = false; //no borders
pp.nUpAutoRotate = false; //no auto rotation
this.print(pp);
Copy link to clipboard
Copied
You need to read the documentation carefully. You can only use this setting from a privileged context, which generally means a script that's installed on the local machine, a batch script ("Action") or from the Console.
And it only applies to the Print dialog itself, not to the file-name dialog which is displayed when printing to a virtual printer.
Copy link to clipboard
Copied
Sorry, but that's not possible. The fileName property does not work in this case, only when you print the file to a .prn file, which is a file that a printer can process directly (usually PostScript). This conflicts with your use of the "Adobe PDF" printer, which produces PDF files.
Either remove the printer name and create .prn files silently, or remove the fileName property and manually specify the name of each PDF file that you generate.
Copy link to clipboard
Copied
But doing as you suggested still gives me a 'save as' dialogue box.
I have tried this:
var pp = this.getPrintParams();
//pp.printerName = "Adobe PDF"; //print to file
pp.interactive = pp.constants.interactionLevel.silent;
pp.fileName = "/C/Users/********/Desktop/New folder/myDoc.prn"
this.print(pp);
Do I have to change anything in the printer settings?
One more thing, is it possible to set printer page size (e.g. "A4", "Letter") in javascript?
Copy link to clipboard
Copied
The code works fine for them. The file is printed to a .prn file without any prompts.
And no, I don't believe you can specify the page size in the code.
Copy link to clipboard
Copied
Of course, the PRN file produced is NOT a PDF file, it needs processing with Acrobat Distiller, and that may fail. No, you cannot do this from JavaScript. It requires a registry change to set the filename, as described in the Acrobat SDK, and JavaScript has absolutely no means to do this.
Copy link to clipboard
Copied
Whatever I do, I can't generate a .prn file- it always show the "save as" dialog box and saves as pdf.
Copy link to clipboard
Copied
Give up, then. This is not intended or expected to work.
Copy link to clipboard
Copied
Even if it did worked for you (which it does for me, as I wrote), what would be the point? A .prn file is pretty useless...
Copy link to clipboard
Copied
Bottom line is, whatever I do, nothing seems to print silently. What is the point of "pp.constants.interactionLevel.silent" then?
Copy link to clipboard
Copied
You need to read the documentation carefully. You can only use this setting from a privileged context, which generally means a script that's installed on the local machine, a batch script ("Action") or from the Console.
And it only applies to the Print dialog itself, not to the file-name dialog which is displayed when printing to a virtual printer.

