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

create a loop for creating fields for a range of pages

Community Expert ,
Oct 06, 2019 Oct 06, 2019

I’m able to create fields on everypages of a PDF using this:

for (var nPage = 0; nPage < this.numPages ; nPage++) {
var f = this.addField("myField", "text", nPage, [200, 600, 300, 660]);
}

or to a specific pages: 

//Page 2
var f = this.addField("myField", "text", 1, [200, 600, 300, 660]);

or all pages except the first or the last.

But now I need to add fields to a specific set of page ex: 2-4, 6. It will probably involve an array with a loop. But I’m lost.
Any clue on how to create an array of pages numbers, and loop the process of creating fields on them? Or any tutorials (simple and clear) on how to create/use arrays and loops would be welcomed.

Thanks!

TOPICS
Acrobat SDK and JavaScript
1.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
Community Expert ,
Oct 07, 2019 Oct 07, 2019

Try this:

for (var nPage in [1, 2, 3, 5]) {
  var f = this.addField("myField", "text", nPage, [200, 600, 300, 660]);
}
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 ,
Oct 07, 2019 Oct 07, 2019
This create a field on the first 4 pages of the doc. Instead of page 2, 3, 4, and 6
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 ,
Oct 07, 2019 Oct 07, 2019
LATEST
Then you must use something other.
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