Skip to main content
Inspiring
March 11, 2022
Question

Creating text box with javascript and changing font

  • March 11, 2022
  • 1 reply
  • 4901 views

I'm having a weird issue trying to select the font for a text box I'm creating with Javascript (to be used in an Action for multiple PDF's).  The code I'm using is below.  This creates a text box in a set location with red text.  However, it keeps using Arial when I want it to be bolded (Arial Black).  I tried the following properties.  I'll list the results below each one.

 

fd.fontWeight = 700;

- This didn't work at all.  I assume it's because addfield doesn't have a fontWeight property

 

fd.fontFamily = "Arial-Black";

- creates the text box with the proper red colour but with a non bold font Arial.

 

fd.fontFamily = Arial-Black;

- creates the text box but in black and with a non bold font Arial.

 

fd.textFont = font.Arial-Black;

- creates the text box but in black and with a non bold font Arial.

 

Can someone tell me how to find the proper font name to use for Arial Black?  For example, I know when using fd.textFont property, you have to use font.HelvB to get Helvetica Bold.  I assume there's some specific name you need to get Arial Black.

 

var fd = this.addField("xftPage"+p+1, "text", p, [TotWidth-450,TotHeight+789,TotWidth-144,TotHeight+729]);
            fd.multiline = true;
            fd.value = "STRICTLY PRIVILEGED AND CONFIDENTIAL – \nTO BE USED FOR PURPOSES OF MEDIATION ONLY";
            fd.textSize=12; fd.readonly = true; 
            fd.fontWeight = 700;   
            fd.alignment="center";
            fd.fontFamily = "Arial-Black";
            fd.textColor = color.red;      

 

This topic has been closed for replies.

1 reply

bebarth
Adobe Expert
March 11, 2022

Hi,
That sould be:

fd.fontFamily = "ArialBlack";

...and you can remove

fd.fontWeight = 700;   

this only work with rich text format.

 

When you don't know the writting of a font, you create a field, change the property of the font, then in the console you write:

console.println(this.getField("fieldName").textFont);

then select all and ENTER of the numeric panel.

@+

try67
Adobe Expert
March 11, 2022

The fontFamily property also only applies to Span objects, not to a Field object.

bebarth
Adobe Expert
March 12, 2022

Correct! Sorry...

Such as you write in the console the property is "textFont" so, you must write:

 

fd.textFont = "ArialBlack";

 

 @+