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

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

Guest
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

1.8K
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 ,
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

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

Votes

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
Guest
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

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

Screen Shot 2016-08-06 at 10.37.19 AM.png

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

Votes

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 ,
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

You must use addScript not addscript.

Votes

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
Guest
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

Thank you, sorry a silly mistake : )

Its working now!

The only issue now is that the print dialog pops up for each document when the action runs on that document; so I have to click cancel before it will process the next document. I need to investigate if there is a way to stop the print dialog popping up whil the action is running ???

Votes

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 ,
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

LOL, yeah, that's a problem... Maybe disable JS in the preferences (Edit - Preferences - JavaScript) before running the Action.

Votes

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
Explorer ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Unfortunately disabling JS in preferences didn't work.

I will look into the option of importing an FDF file to see if this will work. In the short term I'll put up with the print dialog popping up for each document as the action works through them. Thanks everyone for all your help!!  HJ

Votes

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 ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

LATEST

Yeah, of course... My mistake. It can't work because you're using JS to embed the code, of course.

If the Action Wizard wasn't so useless it would have allowed you to define the code to embed in the Document JavaScripts command instead of prompting you to enter it for each file and that would have solved the problem.

Another possible workaround is to add an if-condition that only executes the code if it's not the current date...

Votes

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 ,
Aug 05, 2016 Aug 05, 2016

Copy link to clipboard

Copied

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.

Votes

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 ,
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

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

Votes

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 ,
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

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

Votes

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 ,
Aug 06, 2016 Aug 06, 2016

Copy link to clipboard

Copied

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.

Votes

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