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?
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;
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;
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.
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;
}
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.
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.
Copy link to clipboard
Copied
Thank you!
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.
Peter
Copy link to clipboard
Copied
Sure. Just change this line:
if(oFld.type != "button")
To:
if(oFld.type == "text")
Copy link to clipboard
Copied
Thank you!
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?
Copy link to clipboard
Copied
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.
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?