Skip to main content
ajar
Participant
February 10, 2025
Question

Javascript help in Acrobat form fields

  • February 10, 2025
  • 1 reply
  • 431 views

Good morning,

 

I am working on a fillable PDF form, and my client has asked for the text fields to be formatted in terms of the leading (line spacing) in mutliple line fields. I have the javscript written and it should work, but it doesn't. The fields are set to allow rich text formatting. I added the js code to Format > Custom Format Script. I also checked that the form is javascript enabled. The settings seem correct. Am I missing something?

 

Thank you!

1 reply

try67
Community Expert
Community Expert
February 10, 2025

The setting for line-spacing is not documented, so might not always work. Can you share your code?

ajar
ajarAuthor
Participant
February 10, 2025

Sure! I tried code I found in another discussion on here.

 

var spans = event.richValue;
if (spans !== undefined && event.willCommit) {
for ( var i = 0; i < spans.length; i++ ) {
spans[i].textSize = 17; // font size
spans[i].linespacing = 22 // linespacing

// restore line breaks
if (spans[i].endParagraph) spans[i].text += "\r";

// reset styles to default
spans[i].fontStyle = "normal";
spans[i].fontWeight = 400;
spans[i].strikethrough = false;
spans[i].underline = false;
spans[i].textColor = color.white;
spans[i].alignment = "left";
spans[i].fontFamily = ["Poppins-Medium"];
}

event.richValue = spans;
}

 

It works when you tab out of the field. 

try67
Community Expert
Community Expert
February 10, 2025

I don't see any documentation of an endParagraph property. Is that something you added yourself to the Span object?