Skip to main content
Vu Trong Tri
Participating Frequently
April 15, 2020
Answered

Need a format javascript to bold first line of a text box in interactive PDF

  • April 15, 2020
  • 3 replies
  • 3749 views

Hi everyone,

 

I created an interactive text box (Arial regular) to let the client fill by themselves, in which the first paragraph needs to be bold.

I know I can change it into the rich-text format and press ctrl+B to get bold text, but the client asks me to try.

Any ideas can help me?

 

Thank you.

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom validation script of your field:

 

var v = event.value;
var lines = v.split("\r");
var spans = [];
for (var i=0; i<lines.length; i++) {
	spans.push({text: lines[i]+"\r", fontWeight: (i==0) ? 800 : 500});
}
event.richValue = spans;

3 replies

JR Boulay
Adobe Expert
October 14, 2021

You don't need a script to do this, if you want all the text in bold just select a bold font in the Appearance attributes.

Acrobate du PDF, InDesigner et Photoshopographe
New Participant
October 14, 2021

Hi all,

 

I'm looking for a similar script but then one which makes all text bold in a interactive PDF text box.

Can anyone help me on this one?

 

Thanks.

 

 

try67
Adobe Expert
April 15, 2020

You can use a validation script to change the first line of the text they enter to bold, but it will only happen once they leave the field.

Vu Trong Tri
Participating Frequently
April 16, 2020

That ok! can you please give me that script~

More tutorials are awesome!

try67
Adobe Expert
April 21, 2020

Sorry for the late response!
The first thing is to thank you for your help, but somehow your code works really well, the reason I say "somehow" is because only some pdf files work with this code.

I don't know why but when I added this code it jumped to "held value is not validated", even if they all have the same size, font, setting, format.

Do you have any idea?

Thank you.


Make sure the option for Rich Text Formatting is selected.