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

Creating text box with javascript and changing font

Explorer ,
Mar 11, 2022 Mar 11, 2022

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;      

 

TOPICS
How to , JavaScript
4.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
Community Expert ,
Mar 11, 2022 Mar 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.

@+

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 ,
Mar 11, 2022 Mar 11, 2022

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

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 ,
Mar 11, 2022 Mar 11, 2022

Correct! Sorry...

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

 

fd.textFont = "ArialBlack";

 

 @+

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 31, 2023 May 31, 2023

Could you please provide the source document where you got this syntax, I'd like to learn more about the different properties available and how each one is used. appreciate any feedback.

 

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 ,
May 31, 2023 May 31, 2023

Hi,

Here is a file in which you'll find examples of what it is possible to do.

@+

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 31, 2023 May 31, 2023
LATEST

Very interesting file. I wish it comes with some explanation.

Thank you for posting it.

 

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 ,
May 31, 2023 May 31, 2023

It's all in the JavaScript for Acrobat API Reference, which is a part of the Acrobat SDK:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/

 

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