Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

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

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
2.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 20, 2022 Sep 20, 2022
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.

View solution in original post

Translate
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 15, 2022 Sep 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.

Translate
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

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?

Translate
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

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.

Translate
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

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.

Translate
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

Whatever I do, I can't generate a .prn file- it always show the "save as" dialog box and saves as pdf.

Translate
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

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

Translate
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

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

Translate
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

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

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

Translate
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