Skip to main content
Participant
February 4, 2022
Answered

Adobe PDF Add Text Field with Javascript to all even pages

  • February 4, 2022
  • 3 replies
  • 2828 views

How can I add a text field to all even pages of a pdf document? With the following (:: "text", 1 ::) the text  field is added only to the second page of the document.

 

if ( fld = "undefined" ) {
    var f = this.addField("MacroDate", "text", 1, [550,0,50,15]);
    f.delay = true;
    f.alignment = "center";
    f.fillColor = color.transparent;
    f.lineWidth = 0;
    f.strokeColor = color.black;
    f.borderStyle = border.s;
    f.textSize = 8;
    f.textColor = color.black;
    f.textFont = font.Helv;
    f.readonly = false;
    f.multiline = false;
    f.doNotScroll = true;
    f.value = util.printd("dd/mm/yyyy", new Date());
    f.delay = false;
}

 

This topic has been closed for replies.
Correct answer JR Boulay

You can use this script:

 

for (var p = 0; p < this.numPages; p++) {

var numb = p+1;
if (numb%2 == 0) {
var f = this.addField("MacroDate", "text", p, [550,0,50,15]);
f.delay = true;
f.alignment = "center";
f.fillColor = color.transparent;
f.lineWidth = 0;
f.strokeColor = color.black;
f.borderStyle = border.s;
f.textSize = 8;
f.textColor = color.black;
f.textFont = font.Helv;
f.readonly = false;
f.multiline = false;
f.doNotScroll = true;
f.value = util.printd("dd/mm/yyyy", new Date());
f.delay = false;
}
}

3 replies

JR Boulay
Community Expert
Community Expert
February 4, 2022

However, you should know that there is an easier and built in way to add a date on all even pages:

 

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
February 4, 2022

You can use this script:

 

for (var p = 0; p < this.numPages; p++) {

var numb = p+1;
if (numb%2 == 0) {
var f = this.addField("MacroDate", "text", p, [550,0,50,15]);
f.delay = true;
f.alignment = "center";
f.fillColor = color.transparent;
f.lineWidth = 0;
f.strokeColor = color.black;
f.borderStyle = border.s;
f.textSize = 8;
f.textColor = color.black;
f.textFont = font.Helv;
f.readonly = false;
f.multiline = false;
f.doNotScroll = true;
f.value = util.printd("dd/mm/yyyy", new Date());
f.delay = false;
}
}

Acrobate du PDF, InDesigner et Photoshopographe
Nikos5CEFAuthor
Participant
February 4, 2022

Thank you! That worked perfect

Bernd Alheit
Community Expert
Community Expert
February 4, 2022

The third parameter of this.addField is the page number.

Nikos5CEFAuthor
Participant
February 4, 2022

Yes, but with what should I replace to include all even pages of the document?