Skip to main content
Known Participant
June 17, 2025
Answered

Print page if text entered on them

  • June 17, 2025
  • 1 reply
  • 495 views

I have five text fields - Text1, through Text5, each on a different page of the pdf (Text1 is on page 1, Text2 is on page 2, etc.  I would like to make a print button that would print any pages that contain text.  If only Text1 contains text, then only page 1 would print.  If both Text2 and Text4 both contain text, then pages 2 and 4 would both print, etc..  Is this possible using only one print button?

Correct answer PDF Automation Station

How would this script change for another section of my pdf where the names of the text fields are Client, Case, County, State and City?  In other words, "Text"+i would not work since the text field names are all different.  Thanks.


Create an array of the field names then loop through the array:

var flds=["Client", "Case", "State", "City"];
for(var i=0; i<flds.length; i++)
{
var oFld=this.getField(flds[i]);
if (oFld.value){this.print(false, oFld.page, oFld.page)}
}

1 reply

PDF Automation Station
Community Expert
Community Expert
June 17, 2025

for(var i=1;i<=5;i++)
{
var oFld=this.getField("Text"+i);
if(oFld.value)
{this.print(false, oFld.page, oFld.page)}
}

Known Participant
June 17, 2025

Does this get entered into the "Run a JavaScript" for the button?  Thanks.

PDF Automation Station
Community Expert
Community Expert
June 18, 2025

Yes, with a Mouse Up trigger.