Hide default values on print

New Here ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

109

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Nov 14, 2019 Nov 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;

Likes

translate

Translate

Translate
Adobe Community Professional ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2019 Nov 15, 2019

Copy link to clipboard

Copied

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.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 15, 2019 Nov 15, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines