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

Formatting text field line spacing in JS

Community Beginner ,
Jul 31, 2022 Jul 31, 2022

Is it possible to set line spacing for a text field / variable?

 

var strWord1 = this.getField("CityName").valueAsString;
event.value = strWord1 +" is hosting an event..."

 

I've seen that it can't be done within Form Edit mode. Is it possible with JS?

Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
2.4K
Translate
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 Beginner , Aug 01, 2022 Aug 01, 2022

Ok, so I actually kept looking and I found this amazing custom keystroke script that worked great!

 

var spans = event.richValue;
if (spans !== undefined && event.willCommit) {
for ( var i = 0; i < spans.length; i++ ) {
spans[i].textSize = 10; // font size
spans[i].linespacing = 15; // 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 = fal

...
Translate
Community Expert ,
Jul 31, 2022 Jul 31, 2022

Not possible with a script.

Translate
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 ,
Aug 01, 2022 Aug 01, 2022

Hi,

Given the try67's answer I'm not sure to correctly understand the question, but it is possible to set the line spacing of a text field set in rich text! See the attached file...

@+

Translate
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 ,
Aug 01, 2022 Aug 01, 2022

I stand corrected! However, this is an undocumented property, so use it at your own risk... It does work nicely, though.

Translate
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 Beginner ,
Aug 01, 2022 Aug 01, 2022

Thank you @bebarth for the answer! Sadly I am not skilled enough to look at this document and know how to add it to my script to make it work. Any additional help would be greatly appreciated!

Translate
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 Beginner ,
Aug 01, 2022 Aug 01, 2022

Ok, so I actually kept looking and I found this amazing custom keystroke script that worked great!

 

var spans = event.richValue;
if (spans !== undefined && event.willCommit) {
for ( var i = 0; i < spans.length; i++ ) {
spans[i].textSize = 10; // font size
spans[i].linespacing = 15; // 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.black;
spans[i].alignment = "left";
spans[i].fontFamily = ["Arial"];
}

event.richValue = spans;
}

 

Thanks also to Alex at https://stackoverflow.com/questions/25380882/linespacing-in-multiline-fields

 

Translate
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 ,
May 10, 2024 May 10, 2024
LATEST

Hi, I'm having this same issue, but the keystroke script is not working.  I think it's because I don't have an person typing in the form, but rather the data is being mapped to fields from smartsheet.  Is there a script that would work in the Format section instead of the Keystroke section? 

Vivienne37309854uq2f_0-1715363271736.pngexpand image

 

Translate
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