Can I set a form field fill color to not print?

Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

I have a client who is insisting on making the form fields more visible because she personally has field highlights turned off, so I've added a light gray to all form fields, as well as having an on-focus, on blur that changes the field color to a wash of one of the brand colors when it is active, to make it easier to "see the cursor" for her. (The color changing is only set upon a single field right now for approval prior to setting it up field by field on the doc.)

 

However, in running a test print, I am seeing all of the field fills print in the light gray and the one field with the brand color prints that color. Is there a way to set the fill to not print, while still showing the contents? She's approved the color changing, so if it can be baked into the on-focus, on blur code, that would work great. A few fields have a custom format set up for placeholder script, but other than that, everything is pretty simple, just waiting for user input.

TOPICS
JavaScript, PDF forms

Views

222

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Hi,

 

There is not a specific setting but you could use the "WillPrint" and "DidPrint" of the doc.setAction method to run some code that changes the fill and then puts it back once printing is done.

 

example from docs :

 

//Insert WillSave and DidSave actions. The code gets the file size before //saving and after saving, and compares the two.
// WillSave script
var myWillSave = 'var filesizeBeforeSave = this.filesize;\r'
+ 'console.println("File size before saving is " + ' + ' filesizeBeforeSave );';
// DidSave script
var myDidSave = 'var filesizeAfterSave = this.filesize;\r'
+ 'console.println("File size after saving is "'
+ 'filesizeAfterSave);\r'
+ 'var difference = filesizeAfterSave - filesizeBeforeSave;\r' + 'console.println("The difference is " + difference );\r'
+ 'if ( difference < 0 )\r\t'
+ 'console.println("Reduced filesize!");\r'
+ 'else\r\t'
+ 'console.println("Increased filesize!");'

// Set document actions... 
this.setAction("WillSave", myWillSave); 
this.setAction("DidSave", myDidSave);

 

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
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Okay, starting to read about this document action now, have not used it before. What would be the method of applying no color (I'd prefer no fill to a white fill, for fields that are laid over a few different background colors) to all of the text fields on the page? Would I have to name them one by one in a script? I also have another version of this that will have a spawned template option for users who want to add additional pages of what is basically a spreadsheet to record more entries. If I have to define the fields in the WillPrint action, how would you suggest accounting for added fields?

 

(If this is too much of a headache, I will abandon making this print doc look perfect, but I'm trying to make it look as clean as I can without going off the deep end, given that the client is INSISTING on some extra signifiers of the fields' presence that most users will absolutely not require.)

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
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

(I suppose a much more annoying way to approach this would be to set up a second set of fields that inherit the values of the fields above them, but are hidden but printable, while the entry fields are visible but don't print, but I suspect that will wreak havoc in the spawned pages, so I don't even want to consider that.)

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
Most Valuable Participant ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

If you want to apply it to all fields then you can use the getNthFieldName method and the numFields property to loop over all the fields in the file, setting their fill color to transparent on the Will Print event, and back to Light Grey on the Did Print event.

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
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Ah, my mistake, my test field color was actually set to a darker grey and is not printing in the brand color (I was seriously confused as to why an on-focus/on-blur would cause that anyway), but it was printing the darker fill color so on a grayscale print, I thought it was the brand color.

 

But the question remains, can I set a fill color to be visible on the screen, but not while printing?

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
Adobe Community Professional ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

LATEST

Using the WillPrint is a good option. Use a script like this to remove all the field background.

 

for(var i=0;i<this.numFields;i++)

     this.getField(this.getNthFieldName(i)).fillColor = ["T"];

 

Use the same script on DidPrint to restore the default grey

 

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