Copy link to clipboard
Copied
I have sample text in my fields, which I don't want to print. But, if someone fills out the form, I do want their filled-in information to print. Is this possible to set up?
OK, then you can use this code as the document's Will Print script:
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="button") continue;
if (f.valueAsString==f.defaultValue) f.display = display.noPrint;
else f.display = display.visible;
}
Copy link to clipboard
Copied
Yes. In the document's Will Print event you can enter a script that will set all the fields that have the same value as their default value to hidden (or non-printable), and then set them back to visible on the Did Print event.
Copy link to clipboard
Copied
That's very helpful, thank you! Unfortunately, I'm fairly code illiterate. Does anyone have a sample of code that I could use for this?
Copy link to clipboard
Copied
I can help you with this, but do you have any hidden fields in your file that you don't want to print either way?
Copy link to clipboard
Copied
Thank you! No I do not have any hidden fields. I just want to be able to print the file blank in case people want to fill it out by hand, or have the option to fill it out digitally, and then print their responses.
Copy link to clipboard
Copied
OK, then you can use this code as the document's Will Print script:
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="button") continue;
if (f.valueAsString==f.defaultValue) f.display = display.noPrint;
else f.display = display.visible;
}
Copy link to clipboard
Copied
That worked amazingly! Thank you SO MUCH!!!
Copy link to clipboard
Copied
Hi. I've tried the script you suggested and it still does not hide the fields with default values. I have also tried:
if (Title2.value==Title2.defaultValue) Title2.display = display.noPrint;
else Title2.display = display.visible;
I only have 1 field I need to hide for printing so I figured the straight if else statement should work. But it does not.
Any thoughts?
Copy link to clipboard
Copied
Where does you set the variable Title2? Any error message in the console?
Copy link to clipboard
Copied
Assuming "Title2" is the name of the field, the first line of your code should be:
var Title2 = this.getField("Title2");
Then the rest of it should work...
Copy link to clipboard
Copied
U assumed correctly. I put in the variable declaration but still no dice. I Have 3 fields in the pdf I have swapped out Title2 for those field names to test if it was just Title2 but no. The willPrint script is not executing for any field. Not sure how to bring up the console to check the code. Syntax looks fine though.
Copy link to clipboard
Copied
If the code is accepted when you enter it under Document Will Print it means the syntax is OK. That doesn't mean it doesn't have other issues with it. Press Ctrl+J to open the Console and see if there are any error messages there.
Copy link to clipboard
Copied
It says there's a syntax error. I must not be seeing it:
Copy link to clipboard
Copied
Seems fine to me... Can you post the code as text, though?
Copy link to clipboard
Copied
var Title2 = this.getField("Title2");
if (Title2.value == Title2.defaultValue){
Title2.display = display.noPrint;
} else {
Title2.display = display.visible;
}
Copy link to clipboard
Copied
Works fine for me.
Copy link to clipboard
Copied
Maybe some more information then.
There are 3 fields in the pdf. Name, Title, and Title2
All 3 have the default values set to their field name. Does it matter that the default value is a string and not a raw value?
I have tried setting the javascript from Title2.value to Title2.valueAsString
Still no dice
Copy link to clipboard
Copied
What happens when you execute the code in the console?
Copy link to clipboard
Copied
I receive the syntax error posted in my previous reply.
Copy link to clipboard
Copied
Are you making sure to select the full code before executing it?
Copy link to clipboard
Copied
If I select the whole code, I do not receive the syntax error, but the field is still visible and will print.
Copy link to clipboard
Copied
Well, at least the code is running!
What is the field's default value, and what is its current value?
Copy link to clipboard
Copied
The default value it "Title2", no quotes. For testing, I open the pdf, and go to file->print. I would think that would trigger the willPrint script since the default value was not edited after the pdf was opened.
Copy link to clipboard
Copied
I'll need to see the actual file to be able to help you further with this.
Can you it with us via Dropbox, Google Drive, Adobe Document Cloud, etc.?
Copy link to clipboard
Copied