Skip to main content
Inspiring
April 13, 2021
Question

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

  • April 13, 2021
  • 2 replies
  • 4898 views

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.

This topic has been closed for replies.

2 replies

Inspiring
April 13, 2021

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?

Thom Parker
Community Expert
Community Expert
April 14, 2021

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 19, 2021

Hi Thom,

I'm not sure what I'm doing wrong, but I put that code in both the "Will Print" and "Did Print" Document Actions, but it only removed some of the colors as well as the color of some buttons (??). After printing, the colors didn't come back, either. Any advice???

Thanks in advance!

-Jonathan

BarlaeDC
Community Expert
Community Expert
April 13, 2021

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

 

Inspiring
April 13, 2021

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

Inspiring
April 13, 2021

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