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

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

New Here ,
Jul 29, 2019 Jul 29, 2019

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?

TOPICS
PDF forms

Views

4.7K

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 , 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;

}

Votes

Translate

Translate
Community Expert ,
Jul 29, 2019 Jul 29, 2019

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.

Votes

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

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?

Votes

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

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?

Votes

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

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.

Votes

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

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;

}

Votes

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

Copy link to clipboard

Copied

That worked amazingly! Thank you SO MUCH!!!

Votes

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

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?

Votes

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

Copy link to clipboard

Copied

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

Votes

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

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

Votes

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

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.

Votes

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

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.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

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

    Title2.display = display.noPrint;

} else {

    Title2.display = display.visible;

}

Votes

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

Copy link to clipboard

Copied

Works fine for me.

Votes

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

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

Votes

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

Copy link to clipboard

Copied

What happens when you execute the code in the console?

Votes

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

Copy link to clipboard

Copied

I receive the syntax error posted in my previous reply.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

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.

Votes

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

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?

Votes

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

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.

Votes

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

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

Votes

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

Copy link to clipboard

Copied

Votes

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