Skip to main content
Known Participant
Jun 17, 2025 6:29 PM UTC
Answered

Print page if text entered on them

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?

PDF Automation Station
Community Expert
Jun 18, 2025 3:13 PM UTC

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)}
}

7 replies

PDF Automation Station
Community Expert
Community Expert
Jun 17, 2025 6:59 PM UTC

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

Translate
Known Participant
Jun 17, 2025 11:29 PM UTC

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

Translate
PDF Automation Station
Community Expert
Community Expert
Jun 18, 2025 3:53 AM UTC

Yes, with a Mouse Up trigger.

Translate