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

Adobe PDF Add Text Field with Javascript to all even pages

Community Beginner ,
Feb 04, 2022 Feb 04, 2022

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;
}

 

TOPICS
Edit and convert PDFs , JavaScript , PDF forms
2.4K
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 04, 2022 Feb 04, 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

View solution in original post

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 04, 2022 Feb 04, 2022

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

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 Beginner ,
Feb 04, 2022 Feb 04, 2022

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

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 04, 2022 Feb 04, 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
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 Beginner ,
Feb 04, 2022 Feb 04, 2022

Thank you! That worked perfect

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 04, 2022 Feb 04, 2022
LATEST

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

 

Capture_112.pngexpand image


Acrobate du PDF, InDesigner et Photoshopographe
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