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

Is it possible to set form fields to only print when they're filled in?

New Here ,
Jul 29, 2019 Jul 29, 2019

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?

TOPICS
PDF forms
7.9K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 29, 2019 Jul 29, 2019

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;

}

View solution in original post

Translate
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, 2019 Jul 29, 2019

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.

Translate
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, 2019 Jul 29, 2019

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?

Translate
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, 2019 Jul 29, 2019

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?

Translate
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, 2019 Jul 29, 2019

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.

Translate
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, 2019 Jul 29, 2019

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;

}

Translate
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, 2019 Jul 29, 2019

That worked amazingly! Thank you SO MUCH!!!

Translate
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 ,
Aug 07, 2019 Aug 07, 2019

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?

Translate
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 ,
Aug 07, 2019 Aug 07, 2019

Where does you set the variable Title2? Any error message in the console?

Translate
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 ,
Aug 07, 2019 Aug 07, 2019

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...

Translate
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 ,
Aug 07, 2019 Aug 07, 2019

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.

Translate
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 ,
Aug 08, 2019 Aug 08, 2019

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.

Translate
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 ,
Aug 08, 2019 Aug 08, 2019

It says there's a syntax error.  I must not be seeing it:

Translate
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 ,
Aug 08, 2019 Aug 08, 2019

Seems fine to me... Can you post the code as text, though?

Translate
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 ,
Aug 08, 2019 Aug 08, 2019

var Title2 = this.getField("Title2");

if (Title2.value == Title2.defaultValue){

    Title2.display = display.noPrint;

} else {

    Title2.display = display.visible;

}

Translate
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 ,
Aug 09, 2019 Aug 09, 2019

Works fine for me.

Translate
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 ,
Aug 09, 2019 Aug 09, 2019

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

Translate
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 ,
Aug 09, 2019 Aug 09, 2019

What happens when you execute the code in the console?

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

I receive the syntax error posted in my previous reply.

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

Are you making sure to select the full code before executing it?

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

If I select the whole code, I do not receive the syntax error, but the field is still visible and will print.

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

Well, at least the code is running!

What is the field's default value, and what is its current value?

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

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.

Translate
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 ,
Aug 11, 2019 Aug 11, 2019

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.?

Translate
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 ,
Aug 11, 2019 Aug 11, 2019
Translate
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