Skip to main content
Participant
May 19, 2019
Question

SetPageLabel functionality working in Adobe Pro, but not Reader

  • May 19, 2019
  • 1 reply
  • 539 views

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;

}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 19, 2019

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

Participant
May 19, 2019

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?

Bernd Alheit
Community Expert
Community Expert
May 20, 2019

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