Copy link to clipboard
Copied
Greeting All,
I'm currently trying to create a print button using JavaScript that prints out pages given the page numbers in a field value.
Example:
Field Value: "6, 7, 15, 30, 32, ..." - This field value changes based on the user answers in previous fields.
Print button prints pages 6, 7, 15, 30, 32, ...
Currently copying the field, to the print dialogue box manually, but wondering if there there was way to do all this in 1 button. Any advice is greatly appreciated.
Copy link to clipboard
Copied
You can achieve it using this script:
var pagesString = this.getField("Pages").valueAsString.replace(/\s/g, "");
var pages = pagesString.split(",");
var pagesRanges = [];
for (var i in pages) {
pagesRanges.push([Number(pages[i])-1, Number(pages[i])-1]);
}
var pp = this.getPrintParams();
pp.printRange = pagesRanges;
this.print(pp);
I assumed the field is called "Pages", since you didn't specify it...