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

Conditional formatting of numbers only in event value script (PDF forms)

Explorer ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Running this script in a custom calculation in a text field:

 

event.value = "Words" + this.getField("Number").valueAsString;

 

Would like the value for Number to come out as bold but not the "Words" portion.

If it helps the "Number" is always a numeric value so don't need to get it as a string.

 

Was wondering if that could be used to have it show as bold, that is, can the value type be used in a cusotm format script to make only numbers bold?

 

Thanks all for your help.

 

(P.S. thought asked this question last night, different wording, but is was 3am so maybe not) 

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

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 2 Correct answers

Participant , May 24, 2020 May 24, 2020

Try something like this:

Place the conditional script in the number field and have it output to the text field. You'll need to use an array() to get the conditional formatting you want.

I created a number field formatted as a number and created a text field with no formatting. In the number field I added this custom calculation script:

var v = this.getField("Number1").valueAsString;

var spans = new Array();

spans[0] = new Object();
spans[0].text = "Words: ";
spans[0].fontWeight = 400; // normal weight

s

...

Votes

Translate

Translate
Explorer , May 24, 2020 May 24, 2020

Answered the additional question  (thanks to the Adobe SDK document)

the command is ".textSize" not ".fontSize"  works great

now just to move the big text from the center to the bottom of the field

 

Votes

Translate

Translate
Participant ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Try something like this:

Place the conditional script in the number field and have it output to the text field. You'll need to use an array() to get the conditional formatting you want.

I created a number field formatted as a number and created a text field with no formatting. In the number field I added this custom calculation script:

var v = this.getField("Number1").valueAsString;

var spans = new Array();

spans[0] = new Object();
spans[0].text = "Words: ";
spans[0].fontWeight = 400; // normal weight

spans[1] = new Object();
spans[1].text = v; // insert the value we read from the field
spans[1].fontWeight = 800; // bold

var f = this.getField("Text16");
f.richText = true; // make sure we are dealing with a rich text field
f.richValue = spans;

 

The array gets written to the text field as richtext.

 

Hope this helps.

 

Votes

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
Explorer ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Wow!  That works all right, with a caveat/detail.

The field "Number1" had a simplified field notation calculation in it, if I try to move this calculation up above the script you provided then I get a format error in the value of that field.  If I turn off the number format and just leave it as "none" it gets worse.

 

Of course never testing code for the first time where there is a possibility for circular referncing, I made a new field, called Niumber2 and use in the custom claculation field of Number2 this

var v = this.getField("Number1").valueAsString;

plus the other parts of the script...and it works beautifully!  Thank You!

 

I have no problem with making "dummy" fields.  I actually prefer them, it is clunky but helps with debugging. 

 

One weird thing is the value in the "dummy" field Number2 never updates even though all works well in the output to Tex16...that is instance updates when Number1 changes.  Any reason why and should I worry about Number2 not updating? 

Votes

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
Explorer ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Another question, getting greedy I know,

 

Is it also possible to change the font size for spans[1]?

I tried mimmicing the code with the command 

spans[1].fontSize = 16; 

after the bold command but to no effect and it removes the bold.  Default font size for this field is 9pt in Times New Roman.

Votes

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
Explorer ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Answered the additional question  (thanks to the Adobe SDK document)

the command is ".textSize" not ".fontSize"  works great

now just to move the big text from the center to the bottom of the field

 

Votes

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
Participant ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

I know it will align to the top if you check the "Multi-line" "Allow Rich Text Formatting" checkboxes and uncheck the "Scroll long text" checkbox. Too bad there isn't a way in the properties to align to the bottom.

 

From an Adobe professional:

Although a solution has been provided for you, the fact is that Acrobat is absolutely not a layout program or word processor. The text features within Acrobat are primarily for after-the-fact text touch-up / edit. For what you are attempting, Adobe InDesign or Adobe Illustrator or even Microsoft Word would be a much better solution. And from each of those programs you can save/export PDF.

 

          - Dov

- Dov Isaacs, Principal Scientist, Adobe
 
Seems there should be a way to do it with javascript so that it defaults to bottom alignment but I need to research that.

Votes

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
Explorer ,
May 25, 2020 May 25, 2020

Copy link to clipboard

Copied

LATEST

I do agree with you. 

The base layout is CorelDraw or MSWrod saved as pdf.  Alas the fields are what they are and my users don't like MSWord docs.  In fact what I am creating now was originally an MSWord doc they "hated," too complicate they said....somehow when it is in adoe all is good.   

 

 

 

Votes

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