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

SetPageLabel functionality working in Adobe Pro, but not Reader

New Here ,
May 19, 2019 May 19, 2019

Copy link to clipboard

Copied

Hey All,

Working on a form project and trying to spawn templates that I preset and setPageLabels as they spawn. In an attempt to handle for permutations on which page number additional forms will be rendered to I decided to take the approach of setting labels and deleting them by label when the user clicks on the cross radio button to .value === "Off". The code below works in Pro, but when I attempt to do it in reader only the first page of my templates gets rendered and it is set to the pageLabel of the first 2 pages. Hopefully this is enough context, feel free to follow up with any more questions. Thanks again!

var field = "NewCustomer";

//Sets represented by groupings of templates that will be spawned.

var tcSet = {

  template: "BusinessBankingTMTC",

  label: "Bus Bank TM T & C",

  start: 2,

  pageCount: 27,

  setIndex: 0,

  fields: ["NewCustomer"]

};

var templateSets = [tcSet];

var templateSetsLength = templateSets.length;

var labelExists = function(label) {

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

    if (this.getPageLabel(i) === label + " - " + 1) {

      return true;

    }

  }

  return false;

}

var reorganizeTempSets = function(currentSet, templateSets) {

  if (currentSet.setIndex === templateSets.length - 1) {

    return;

  }

  for (var i = currentSet.setIndex; i < templateSets.length - 1; i++) {

    templateSets[i + 1].start = templateSets.start + templateSets.pageCount;

    templateSets[i + 1].setIndex = i;

  }

}

var spawnTemplateWithLabel = function(set) {

  if (labelExists(set.label)) {

    reorganizeTempSets(set, templateSetsLength);

    return;

  }

  var name = set.template;

  var start = set.start;

  var label = set.label;

  var pageCount = set.pageCount;

  for (var i = 1; i <= pageCount; i++) {

    if (i >= 10) {

      this.getTemplate(name + "_" + i).spawn(start + i - 1, false, false);

      this.setPageLabels(start + i - 1, ["D", label + " - ", i]);

    } else {

      this.getTemplate(name + "_0" + i).spawn(start + i - 1, false, false);

      this.setPageLabels(start + i - 1, ["D", label + " - ", i]);

    }

  }

}

var deletePagesByPageLabel = function(set) {

  var startPage;

  var currentField = field;

  if (shouldDelete(set.fields, currentField)) {

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

      if (this.getPageLabel(i) === set.label + " - " + 1) {

        startPage = i;

      }

    }

    if (startPage) {

      this.deletePages(startPage, startPage + set.pageCount - 1);

    }

  }

  page = 0;

}

var shouldDelete = function(fields, currentField) {

  var potentialActiveField;

  for (var i = 0; i < fields.length; i++) {

    potentialActiveField = this.getField(fields).value;

    if (potentialActiveField !== "Off" && fields !== currentField) {

      return false;

    }

  }

  return true;

}

if (this.getField(field).value === "Off") {

  this.templates.sort(function(a, b){ return a - b });

  for (var i = 0; i < templateSets.length; i++) {

    spawnTemplateWithLabel(templateSets);

  }

  this.pageNum = 0;

} else {

  this.templates.sort(function(a, b){ return a - b });

  deletePagesByPageLabel(tcSet);

  this.pageNum = 0;

}

TOPICS
Acrobat SDK and JavaScript

Views

123

Likes

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 ,
May 19, 2019 May 19, 2019

Copy link to clipboard

Copied

Correct, this method can't be used in Reader.

Likes

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
New Here ,
May 19, 2019 May 19, 2019

Copy link to clipboard

Copied

meh. Figured as much - thanks for confirming. Do you have any best practices for approaching spawning/deleting for both Pro and Reader (V11 and up) where multiple form fields may render the same template and the spawned templates order is non-deterministic because the user can click on one form field before the other?

Likes

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 ,
May 20, 2019 May 20, 2019

Copy link to clipboard

Copied

LATEST

You can store the page labels in a hidden form field.

Likes

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