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

Concatenate Fields with Bold Text

Community Beginner ,
Jul 18, 2019 Jul 18, 2019

Hello.  I am using Adobe Acrobat XI Pro and am creating a form which concatenates several text fields into one.  Some of the text needs to be in a bold font and the rest are not.  I am using a Custom Calculation Script as follows:

// Get the field values, as strings

var s1 = getField("Paragraph1").valueAsString;

var s2 = getField("FName").valueAsString;

var s3 = getField("LName").valueAsString;

var s4 = getField("DateIssued").valueAsString;

var s5 = getField("Paragraph2").valueAsString;

// Combine values, separated by a space

event.value = s1 + " " + s2 + " " + s3 + " on " + s4 + ".  " + s5;

I would like the text fields "FName" and "LName" to be bold, but the rest are not.  I have tried searching this and can not find a resolution to my question.  Can someone help please?  Thank you.

TOPICS
Create PDFs
1.3K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 18, 2019 Jul 18, 2019

You can do it by defining the field as having Rich Text Formatting (under Properties, Options), but then the script has to be amended to the following:

var s1 = getField("Paragraph1").valueAsString;

var s2 = getField("FName").valueAsString;

var s3 = getField("LName").valueAsString;

var s4 = getField("DateIssued").valueAsString;

var s5 = getField("Paragraph2").valueAsString;

var spans = [];

var span1 = {};

span1.text = s1 + " ";

spans.push(span1);

var span2 = {};

span2.text =  s2 + " " + s3;

span2.fontWeight = 700

spans.push(span2);

var span3 = {};

span3.text = " on " + s4 + ".  " + s5;

spans.push(span3);

event.richValue = spans;

View solution in original post

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 ,
Jul 18, 2019 Jul 18, 2019

You can do it by defining the field as having Rich Text Formatting (under Properties, Options), but then the script has to be amended to the following:

var s1 = getField("Paragraph1").valueAsString;

var s2 = getField("FName").valueAsString;

var s3 = getField("LName").valueAsString;

var s4 = getField("DateIssued").valueAsString;

var s5 = getField("Paragraph2").valueAsString;

var spans = [];

var span1 = {};

span1.text = s1 + " ";

spans.push(span1);

var span2 = {};

span2.text =  s2 + " " + s3;

span2.fontWeight = 700

spans.push(span2);

var span3 = {};

span3.text = " on " + s4 + ".  " + s5;

spans.push(span3);

event.richValue = spans;

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 ,
Jul 18, 2019 Jul 18, 2019

Thank you for sending this out.  I am not sure if I did something wrong, because my fields are no longer combining and the names did not bold.  I did go to options and change the setting to Allow Rich Text Formatting.  Any suggestions?

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 ,
Jul 18, 2019 Jul 18, 2019

Did you place the script as a custom calculation script?

Are there any error messages in the console window?

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 ,
Jul 18, 2019 Jul 18, 2019
LATEST

I got it to work.  Your code was spot on, I just fat fingered some stuff. Thank you

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