Skip to main content
Known Participant
September 15, 2022
Answered

Javascript- Acrobat print to file 'silently' is asking for a file name in 'save as' dialog box.

  • September 15, 2022
  • 1 reply
  • 3354 views

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

 

This topic has been closed for replies.
Correct answer try67

Bottom line is, whatever I do, nothing seems to print silently. What is the point of "pp.constants.interactionLevel.silent" then?


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.

1 reply

try67
Community Expert
Community Expert
September 15, 2022

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.

Known Participant
September 17, 2022

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?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 20, 2022

Bottom line is, whatever I do, nothing seems to print silently. What is the point of "pp.constants.interactionLevel.silent" then?


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.