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

Formatting text field line spacing in JS

Community Beginner ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

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

Views

166

Likes

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

...

Likes

Translate

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

Copy link to clipboard

Copied

Not possible with a script.

Likes

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

Copy link to clipboard

Copied

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...

@+

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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!

Likes

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

Copy link to clipboard

Copied

LATEST

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

 

Likes

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