Skip to main content
Participant
June 8, 2020
Question

Printing using javascript based on pages in the field

  • June 8, 2020
  • 1 reply
  • 524 views

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. 

 

 

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 8, 2020

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...