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

Community Beginner ,
Sep 15, 2022 Sep 15, 2022

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

 

TOPICS
Create PDFs , Edit and convert PDFs , JavaScript , Print and prepress

Views

71

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
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 20, 2022 Sep 20, 2022

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.

Likes

Translate

Translate
Community Expert ,
Sep 15, 2022 Sep 15, 2022

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.

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
community guidelines
Community Beginner ,
Sep 17, 2022 Sep 17, 2022

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?

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
community guidelines
Community Expert ,
Sep 17, 2022 Sep 17, 2022

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.

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
community guidelines
LEGEND ,
Sep 18, 2022 Sep 18, 2022

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.

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
community guidelines
Community Beginner ,
Sep 19, 2022 Sep 19, 2022

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.

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
community guidelines
LEGEND ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Give up, then. This is not intended or expected to work. 

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
community guidelines
Community Expert ,
Sep 20, 2022 Sep 20, 2022

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...

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
community guidelines
Community Beginner ,
Sep 20, 2022 Sep 20, 2022

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?

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
community guidelines
Community Expert ,
Sep 20, 2022 Sep 20, 2022

Copy link to clipboard

Copied

LATEST

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.

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
community guidelines

Make content for your business needs with Adobe Express.

Get started easily with free templates: