Skip to main content
Participant
December 12, 2020
Answered

Is there a script to not print pages that don't have data in specific fields?

  • December 12, 2020
  • 1 reply
  • 1172 views

I have a series of documents that are used regularly, that have four pages in the middle that contain text fields for the user to add information (all other pages have fields too, but those will always be filled out and will always need to be printed).  Each document is 15-20 pages long and the four pages I'm concerned with are in the middle somewhere (for this example, we can say they are pages 3,4,5, and 6).  If a user fills out the form but only needs to complete pages 3, and 4, is there a way to make a print button that will print every page except the two pages with text fields that have no user data (in this case, pages 5 and 6)?  

I'm trying to avoid having users print two pages without data, and also trying to avoid users having to go to  the organize pages tool and delete pages before printing.  I know they could choose print page range and choose to print pages 1-4 and 7-15, but they won't.  I'm just hoping someone has a print button that avoids printing a page if a specific field has no user data (or perhaps knows of how to complete that task within the properties of that specific form field).

Thank you in advance!

Mike

Correct answer try67
Yes,
Affiant Statement 2 (page x)
Affiant Statement 3 (page x+1)
Affiant Statement 4 (page x+2)
Affiant Statement 5 (page x+3)

I used x because some documents have 3 pages before Affiant Statement 1
(which will always print) and some documents have 2 pages before Affiant
Statement 1.

Try this code:

 

var pp = this.getPrintParams();
var pagesToPrint = [];
pagesToPrint.push([0,1]); // always print pages 1-2
if (this.getField("Affiant Statement 2").valueAsString!="") 
	pagesToPrint.push([2,2]); // print page 3 if "Affiant Statement 2" is not empty
if (this.getField("Affiant Statement 3").valueAsString!="") 
	pagesToPrint.push([3,3]); // print page 4 if "Affiant Statement 3" is not empty
if (this.getField("Affiant Statement 4").valueAsString!="") 
	pagesToPrint.push([4,4]); // print page 5 if "Affiant Statement 4" is not empty
if (this.getField("Affiant Statement 5").valueAsString!="") 
	pagesToPrint.push([5,5]); // print page 6 if "Affiant Statement 5" is not empty
pagesToPrint.push([6,14]); // always print pages 7-15
pp.printRange = pagesToPrint;
this.print(pp);

1 reply

try67
Community Expert
Community Expert
December 12, 2020

Yes, this is possible to achieve using a script. What are the names of the fields you wish to check on each one of those pages?

Participant
December 13, 2020

Consectutive pages with Text Fields labeled "Affiant Statement P2" then "Affiant Statement P3" 

try67
Community Expert
Community Expert
December 13, 2020

Aren't there four pages? Shouldn't there also be four fields, then?