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

PDF field formatting for blank underline

New Here ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

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.

TOPICS
JavaScript , PDF forms

Views

1.4K

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 , Dec 30, 2022 Dec 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
...

Votes

Translate

Translate
Community Expert ,
Dec 29, 2022 Dec 29, 2022

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 29, 2022 Dec 29, 2022

Copy link to clipboard

Copied

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?

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

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

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

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

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

that absolutely works!  Is there a way to do this on multi line text boxes?  So if I have a multi line text box that is 8 rows of text tall, is there a way to make it line the box for print and manual filling?

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

You mean underline each line? If so, then no.

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

Well you have been a big help thank you!

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 ,
Dec 30, 2022 Dec 30, 2022

Copy link to clipboard

Copied

LATEST

The multiline field would be handled with my first suggestion, Use rich text with an underline font. 

 

 

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

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