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.
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);
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.)
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.)
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.
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi,
Can you share the document with the updates so that we can check it ? Are there any errors in the console?
Copy link to clipboard
Copied
I just sent you a DM with the info. Thank you!!!!!!!
Copy link to clipboard
Copied
Hi,
Worked out the problem, not entirely sure why it is a problem, but you have a field name "Vapor Barrier Application Method" and when we try to use that in the code
this.getField(this.getNthFieldName(i)).fillColor = ["T"];
it is not returning a field object. So I changed it's name to "VBAM" and that let me get it further but I ran into the same problem with another field called "List Base Sheet Brand " Which I change to "LBSB" and then the code was able to complete. I don't really have an explanation for why that would work but I do have a couple of tips in naming which have saved me hours of pain in the past.
1. Only use A-z0-9, underscore (I don't even do that) for field names,
2. Don't use spaces, I use CamelCase so "Vapor Barrier Application Method" would become "VaporBarrierApplicationMethod"
3. Keep that name short, it is only for programming, you can set what the user sees in terms of default text to whatever you want, so the above name would become "VaporBarrierMethod" or even "VBAM" (but that might be going to far)
But by doing this I have been able to avoid some of Acrobat JavaScript's idiosyncrasies.
Copy link to clipboard
Copied
The getNthFieldName method can sometimes return names of corrupt or missing fields (especially if they were created elsewhere, like in InDesign). This is why I always add a check to see if the field object returned by getField is null before doing anything else with it.
So instead of this:
this.getField(this.getNthFieldName(i)).fillColor = ["T"];
Use this:
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f!=null) f.fillColor = ["T"];