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

Is it possible to create a Print Button that executes a Javascript that will print pages with one specific form field completed?

Explorer ,
Feb 15, 2017 Feb 15, 2017

I have a 20 page form that we use for performance documentation on new employees. Most of the time, only a few pages are used. I would like to create a print button that, when clicked, executes a java script that will only print a range of pages (one range only) that have been filled out.


I want to do this by utilizing the page numbers. At the bottom of each page, I have a "Page X of Y" area (where X is the current page and Y is the total number of pages). The Y fills out automatically with the total number of pages after a number is entered (User types in 5, it duplicates across the form for all pages).

I want to somehow use the X form field as the indicator whether to print the page or not.

Is this possible? Anyone have any idea what the Java script would even be?

Thank you so much for your input in this matter!

TOPICS
Acrobat SDK and JavaScript , Windows
1.7K
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

correct answers 1 Correct answer

Community Expert , Feb 15, 2017 Feb 15, 2017

Ok - Stop what you're doing. Back away slowly and don't make any sudden movements.

There are far better ways to approach what you're trying to do.

You don't need a 20 page file. You need a two page file and a template page that can be spawned as number of times as needed. If you use page templates, you'll always have a document that's exactly as long as you need it to be and no longer. Read the article at the link below. It's old but the concepts are still valid, the code probably even still works

...
Translate
Community Expert ,
Feb 15, 2017 Feb 15, 2017

Without knowing the field names, it'd be impossible to tell you what the script would be but creating it would be relatively simple if you have any experience with JavaScript at all.

First iterate over the fields you are using for X and determine which ones have a value that's not an empty string. Get the page number for that field using the Field.page property. Then use those numbers to set the PrintParams.printRange property.

J-

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
Explorer ,
Feb 15, 2017 Feb 15, 2017

I just checked, the form fields are called Page1, Page2, Page3, etc...

Unfortunately my knowledge of javascript is about as rudimentary as possible. I have dabbled a bit with using it in forms, but I have done heavy research into it before creating even the simplest of scripts.

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 ,
Feb 15, 2017 Feb 15, 2017

So... I'm not understanding something.

Is the value of the field "Page1" always "1" and the value of the field "Page2" always "2"? If that's the case, the value of the fields that represent X are irrelevant, you just need the value of Y.

Or is it possible that the 3rd page in the 20 page PDF is labeled Page 1 of 5 for example? If this is the case, you'll and the range is always continuous, then you have a bit more work to do but it's a relatively simple use of Math.max and Math.min methods to get the range.

We can't really give you copy/paste scripts without having the form in question to play with... at least, not for this sort of thing.

If you want to understand JavaScript in Acrobat, start here...

Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

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
Explorer ,
Feb 15, 2017 Feb 15, 2017

Here is a link to the form if you would like to visualize this, it'll be much easier. Basically, yes, the pages will be sequential, however the form is made so that in case someone needs in excess of 20 pages, they can open another copy of the same form and go from there.

Also, I was just thinking that basing the script off of a field that could be blank vs filled would be the easiest way to do this. So "Page1" will almost always be "1" and "Page2" will almost always be "2" and "Page10" will be "10", but Page11, Page12, etc will be empty and, ergo, should not print.

Does that make sense? lol

https://drive.google.com/open?id=0B5bYIiGSQzueNGhhalBoTUltbjQ

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 ,
Feb 15, 2017 Feb 15, 2017

Ok - Stop what you're doing. Back away slowly and don't make any sudden movements.

There are far better ways to approach what you're trying to do.

You don't need a 20 page file. You need a two page file and a template page that can be spawned as number of times as needed. If you use page templates, you'll always have a document that's exactly as long as you need it to be and no longer. Read the article at the link below. It's old but the concepts are still valid, the code probably even still works.

Planet PDF - A Lesson in Templates for Adobe Acrobat

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
Explorer ,
Feb 15, 2017 Feb 15, 2017

OH MY GOD YOU ARE AMAZING!!!! Yes this will be MUCH easier to do!! Fantastic! Thank you so much!!!!

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
Explorer ,
Feb 15, 2017 Feb 15, 2017
LATEST

Joel, I have a followup question about the Spawn and page templates but it doens't fit this topic. Link is below in case you had any knowledge of this one too. Thank you again!

Using a page template and spawn, but I don't want one particular field to be renamed to the new page...

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
Explorer ,
Feb 15, 2017 Feb 15, 2017

Also, thank you for that link! I'm checking it out right now.

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