Skip to main content
markok7
Participant
January 14, 2019
Question

Making fontWeight work?

  • January 14, 2019
  • 4 replies
  • 1123 views

I'm using the fontWeight method to try to set the font of a text field to bold.

I loop through all the fields, and let's say the field I'm looking to make bold is called "Number":

loop

{

get name //cFieldName

get field of name //oField

if(cFieldName == "Number"){oField,fontWeight = 700;}

}

in the javascript API manual it says fontWeight 700+ is considered bold, but when the script runs without errors, it doesn't change the font weight at all. I'm editing fontSize and textFont in the same script and they work, so it's not a question of the structure of the script, I don't think.

This topic has been closed for replies.

4 replies

Legend
January 14, 2019

Do you see a bold version of PTSans in the pull down list of fonts? The font MUST EXIST. Acrobat will not turn a nonbold font into bold, as Word will.

Legend
January 14, 2019

Yes, choose the bold weight of the font (which MUST be installed) by its name. If in doubt, what is the font name?

markok7
markok7Author
Participant
January 14, 2019

PTSans is the font that I am using. I'd like to avoid span objects if possible. Could you give me an example of setting it to bold for the field?

Thom Parker
Community Expert
Community Expert
January 14, 2019

Look through the font selections on the Appearance tab of the field properties. Notice how there are bold, italic and other versions of the fonts.  The Bold bit is really a different version of the font, that's provided in the font file.  So, bold is selected by selecting the bold version of the font. Of course, not all fonts provide bold versions.

You can find the bold name by selecting it on the properties dialog (shown below) and then using the console window to show the name used in JavaScript, like this.

this.getField("Text1").textFont;

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
January 14, 2019

It looks like there is part of the script missing. You seem to just be executing this:

{oField,fontWeight = 700;} Also, the only fontWeight property I see is for the Spans object.

markok7
markok7Author
Participant
January 14, 2019

I see, so is there a way to make the font of a text field bold in another way?

Bernd Alheit
Community Expert
Community Expert
January 14, 2019

Use span objects or use a other font.

Bernd Alheit
Community Expert
Community Expert
January 14, 2019

Fields doesn't have the property fontWeight.