Skip to main content
Participant
December 28, 2022
Answered

PDF field formatting for blank underline

  • December 28, 2022
  • 2 replies
  • 3183 views

I have a few forms that are fillable and are utilized in their digital format and as a printable copy to utilize while out in the field.  Instead of having an underscore on the base document, is there a way to make the form field box act like the underline?  So basically if the form field is blank underline the lower portion of the entire blank box, but if there is text only underline the portion of the box that contains text.

This topic has been closed for replies.
Correct answer try67

It's easier to implement on the print event, I think, although it's also possible to do it on the screen, but that might cause some delays in the file. If you want to try it out apply the following code as the custom Calculation script of any text field in the file:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="text") {
		if (f.valueAsString=="") {
			f.borderStyle = border.u;
			f.lineWidth = 1;
			f.strokeColor = color.black;
		} else {
			f.borderStyle = border.s;
			f.lineWidth = 0;
			f.strokeColor = color.transparent;			
		}
	}
}

2 replies

try67
Community Expert
Community Expert
December 29, 2022

You can do it by changing the field's stroke line style, but do you want this to only appear on the printed copy, or also on the screen?

LiverebelAuthor
Participant
December 30, 2022

I would like for it to appear on both, but if this is a monumental task on the printed copy would work as well.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 30, 2022

It's easier to implement on the print event, I think, although it's also possible to do it on the screen, but that might cause some delays in the file. If you want to try it out apply the following code as the custom Calculation script of any text field in the file:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="text") {
		if (f.valueAsString=="") {
			f.borderStyle = border.u;
			f.lineWidth = 1;
			f.strokeColor = color.black;
		} else {
			f.borderStyle = border.s;
			f.lineWidth = 0;
			f.strokeColor = color.transparent;			
		}
	}
}
Thom Parker
Community Expert
Community Expert
December 29, 2022

That's tricky, but it could be done by making the field "Rich Text", with an underline text property, and using a format script to display underlines when the field is empty. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often