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

create a loop for creating fields for a range of pages

Community Expert ,
Oct 06, 2019 Oct 06, 2019

Copy link to clipboard

Copied

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

Views

751

Translate

Translate

Report

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

Copy link to clipboard

Copied

Try this:

for (var nPage in [1, 2, 3, 5]) {
  var f = this.addField("myField", "text", nPage, [200, 600, 300, 660]);
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

This create a field on the first 4 pages of the doc. Instead of page 2, 3, 4, and 6

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST
Then you must use something other.

Votes

Translate

Translate

Report

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