• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

Views

488

Likes

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

Community Expert , 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
Community Expert ,
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

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

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
Community Expert ,
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

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 ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Hi-This thread is old so I realize I may need to start a new one. I'm trying to figure out how to have the default values not print as well. Non of the above scripts are working although I may be doing it wrong. When I print on my printer, the default values don't print. But when I use FedEx online printing, they show up. I know nothing about Javascript. Thanks in advance for any help.

Likes

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
Community Expert ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

That would suggest the problem is with the FedEx online printer, then, which is not surprising. I doubt such a printer will execute scripts that are under the document's Will Print event. If you want to use that type of printer then you have to first hide those fields on your end, and then send the file to it.

Likes

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 ,
Jul 30, 2021 Jul 30, 2021

Copy link to clipboard

Copied

Thank you!

Likes

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
Community Beginner ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

wow, thank you for script. Is it possible to apply this only on interactive "textfields", because script is also applied rules on checkboxes, and now they are not visible on printed document, until they are checked. 
sorry for my EN.

checkbox.jpg

 

Peter

Likes

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
Community Expert ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Sure. Just change this line:

if(oFld.type != "button")

To:

if(oFld.type == "text")

Likes

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
Community Beginner ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Thank you!

Likes

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
Community Beginner ,
Nov 06, 2022 Nov 06, 2022

Copy link to clipboard

Copied

One last question. Interactive textfields with default values are visible on cell phone web browser, but they are not editable, but that wouldnt be a problem at all... Problem is that form cannot be printed without that default values, so form is not fillalbe with pen. Is it possible to set default values to be not visible for incompatible pdf readers?

Likes

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
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

LATEST

If a PDF viewer does not support JavaScript or other interactive features, then there is no way to dynamically change or modify a form field property, or other PDF property for that viewer. However, you can do it the other way around. Setup the initial field/form properties to the worst case non-supporting/compatible viewer. Then use a script to set things right for the viewers that do support interactive features. 

 

 

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

Likes

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
Community Beginner ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

One last question. Interactive textfields with default values are visible on cell phone web browser, but they are not editable. That wouldnt be a problem at all... Problem is that form cannot be printable without that default values. They stays there, so form can not be filled in with a pen. Is it possible to set the default values so that they will be not visible on incompatible pdf readers?

Likes

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