Skip to main content
noram65782408
Participant
November 19, 2019
Answered

Why does this javascript only work for 2 page documents? Trying to use it for a 3 page document

  • November 19, 2019
  • 2 replies
  • 667 views

Hello,

 

IT guy for a small company here. I'm attempting to use a javascript file to print a number in the bottom corner of each page of a document, then incrementally for each copy of the document.

 

This JS works for 2 page documents but when I try to use the same code for a 3 page document to do the exact same thing it only prints the number on the first two pages

 

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<AcroForm>
//<ACRO_source>Print:Annot1:MouseDown:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Print:Annot1:MouseDown:Action1 ***********/
var snum = app.response("Please Enter Starting Number","");
var f = this.getField("Serial Number");
f.value = snum;
var copies = app.response("Please Enter Number of Copies to Print","1");

if (copies == null || copies ==="" || copies === 0) {
txt = "No Copies Printed";
} else {
for (i=0; i < copies; i++) {
f.value = Number(f.value)+1;
var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.silent;
this.print(pp);
}
}

//</ACRO_script>
//</AcroForm>

 

admittedly I have no experience with JS and this script was set up by the guy I replaced (whether he wrote it himself or found it online i'm unsure). 

This topic has been closed for replies.
Correct answer Test Screen Name

The script doesn't add the field. So you have to put the field there yourself before running it. (My guess is someone did this for two pages, and it wasn't done when a third page was added).

2 replies

Test Screen NameCorrect answer
Legend
November 19, 2019

The script doesn't add the field. So you have to put the field there yourself before running it. (My guess is someone did this for two pages, and it wasn't done when a third page was added).

noram65782408
Participant
November 20, 2019

This was it! Thank you both so much. 

Bernd Alheit
Community Expert
Community Expert
November 19, 2019

Does you add the field "Serial Number" on all 3 pages?

noram65782408
Participant
November 19, 2019

No, it doesn't. The number prints like normal on the first 2 pages but nothing at all on the 3rd. It doesn't actually print the string "serial number" anywhere on the sheets themselves, even on the first 2 pages. 

Bernd Alheit
Community Expert
Community Expert
November 19, 2019

I mean the field with this name.