Creating text box with javascript and changing font
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
@+
Copy link to clipboard
Copied
The fontFamily property also only applies to Span objects, not to a Field object.
Copy link to clipboard
Copied
Correct! Sorry...
Such as you write in the console the property is "textFont" so, you must write:
fd.textFont = "ArialBlack";
@+
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi,
Here is a file in which you'll find examples of what it is possible to do.
@+
Copy link to clipboard
Copied
Very interesting file. I wish it comes with some explanation.
Thank you for posting it.
Copy link to clipboard
Copied
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/

