Skip to main content
Participant
November 14, 2019
Answered

Hide default values on print

  • November 14, 2019
  • 1 reply
  • 2124 views

I am trying to create a pdf form that hides default values on print, but will print entered values. Is there a way to do this through javascript?

This topic has been closed for replies.
Correct answer Thom Parker

Yes,

Write a script for the WillPrint event that will test all fields. If the field contains the default value, then set it's display property to "display.noPrint"

 

Here's the meat of the script

 

var oFld = this.getField(strFieldName);

oFld.display = (oFld.value == oFld.defaultValue)?display.noPrint:display.visible;

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 14, 2019

Yes,

Write a script for the WillPrint event that will test all fields. If the field contains the default value, then set it's display property to "display.noPrint"

 

Here's the meat of the script

 

var oFld = this.getField(strFieldName);

oFld.display = (oFld.value == oFld.defaultValue)?display.noPrint:display.visible;

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
November 15, 2019

Thanks, I pasted that script into the will print event, but it appears to be missing something. Do I need to define strFieldName? Apologies, I am not well versed in javascript.

Thom Parker
Community Expert
Community Expert
November 15, 2019

Yes, "strFieldName" was just a place holder for the field name.

Becaue, this is only one line of code, for hidding one field on print. It needs to be extended to all fields on the form.

 

Like this:

 

for(var i=0;i<this.numFields;i++)

{

    var oFld = this.getField(this.getNthFieldName(i));

    if(oFld.type != "button")

         oFld.display = (oFld.value == oFld.defaultValue)?display.noPrint:display.visible;

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often