Skip to main content
August 5, 2016
Question

Action or Javascript to set a group of PDFs to open print dialog automatically

  • August 5, 2016
  • 3 replies
  • 2166 views

For an individual PDF I can configure it to open the print dialog when it opens.

For instance in Acrobat DC I can go to:

Page Thumbnails > select all pages and then go to 'Page Properties'. Under Page Properties you can go to Action > Page Open > Execute a menu item (File>Print). Alternatively I can execute a document level javascript such as:

This.print();

However I have a lot of PDFs that I want to set to open the print dialog automatically.

Ideally I want to run something that automatically updates all the PDFs in a folder with the above settings to open the print dialog automatically. Ideally I'd use an Acrobat Action but I can't see how to set it up to do what I want. Does anyone know how to do this?

Many thanks, HJ.

This topic has been closed for replies.

3 replies

Inspiring
August 6, 2016

It is also possible to add a document level JavaScript through the importing of an FDF file.

Automatic Insertion of Document-Level JavaScripts by D.P. Story

try67
Community Expert
Community Expert
August 6, 2016

The question is whether or not that action will trigger the code at the moment you import the FDF file...

Inspiring
August 6, 2016

If you write the script as a function, you can add the function call to the script or you can use the "After" JavaScript action in the FDF to call the function. See Example 3 at the end of the linked article. One can create a button to import the FDF into Reader which has an unexpected result.

Inspiring
August 5, 2016

It is possible to declare a variable that can be set to show that you script ran once and skips running it a second time.

The following script can be placed on the page open action.

// see if control variable exist;

ifItypeof bPrintUI == "undefined")

{

// does not exist so define it as false;

var bPrintUI = false;

}

// see if print ui has been opened

if(bPrintUI != true)

{

// it has not;

bPrintUI = true; // set to have been opened;

this.print(); // display print dialog;

}

If you place this only on the first page, the script will not run if the PDF is opened to another page.

try67
Community Expert
Community Expert
August 5, 2016

Your way of doing it will work, but it's not very good because it means that the Print dialog will open not just when the file is opened, but each time the user views the first page of the file. For example, if you scroll to the second page and then back to the first the Print dialog will open again, using your method.

A better way is to embed a code at the doc-level, which will open the Print dialog only when the file is opened.

This can also be done as a part of an Action, in Acrobat Pro, and applied to multiple files at once.

Basically, all you have to do is create a new Action (via Tools - Action Wizard) with the following JS code (and a Save command), and then run it on your files:

this.addScript("load", "this.print();");

August 6, 2016

Many thanks for your help. I've tried the following but unfortunately it doesn't seem to work.

1. I create an action

2. I add an "Execute JavaScript" action

3. In the "Execute Javascript" action I added the following code:

/* Set Print Dialog to open automatically */

this.addscript("load", "this.print();");

I tried running the action on a single file as well as multiple files. In both cases when I re-open any of the files the print dialog doesn't automatically open?

Perhaps I need to add something to the javascript to ensure it runs at the doc open event? Also after running the action I go to Tools > Javascripts > Document Javascripts. I thought I would see the print script there but its not?

Many thanks for your help!!

HJ

Bernd Alheit
Community Expert
Community Expert
August 6, 2016

You must use addScript not addscript.