Making fontWeight work?

New Here ,
Jan 14, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

145

Likes

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

Making fontWeight work?

New Here ,
Jan 14, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

146

Likes

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
Jan 14, 2019 0
Adobe Community Professional ,
Jan 14, 2019

Copy link to clipboard

Copied

Fields doesn't have the property fontWeight.

Likes

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
Reply
Loading...
Jan 14, 2019 0
Most Valuable Participant ,
Jan 14, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Jan 14, 2019 0
New Here ,
Jan 14, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 14, 2019 0
Adobe Community Professional ,
Jan 14, 2019

Copy link to clipboard

Copied

Use span objects or use a other font.

Likes

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
Reply
Loading...
Jan 14, 2019 0
Most Valuable Participant ,
Jan 14, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 14, 2019 1
New Here ,
Jan 14, 2019

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Jan 14, 2019 0
Adobe Community Professional ,
Jan 14, 2019

Copy link to clipboard

Copied

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;

Likes

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
Reply
Loading...
Jan 14, 2019 0
New Here ,
Jan 14, 2019

Copy link to clipboard

Copied

I've tried this actually to no avail. I can set the font to PT Sans using javascript but it actually recognizes a different string than the one in the dropdown in the Appearance tab, namely "PTSans".

I've tried "PTSansBold", "PT Sans Bold", "PT Sans-Bold". I haven't been able to find a library of font strings for javascript API in adobe acrobat.

Likes

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
Reply
Loading...
Jan 14, 2019 0
Adobe Community Professional ,
Jan 14, 2019

Copy link to clipboard

Copied

I implied, but didn't actually point out that the name used in JavaScript is different than the name shown on the drop down. Which is why I suggested you find out the name used in JavaScript by using the console script.  But I believe I did point out that the bold font is actually a version of the main font that must be provided by the font file. If its not on the list, then it's not available.

You also have another issue. The fonts listed are the fonts available on your system.  Its fine for you to set the font with a script, but if that font is not available on the user's system, then setting it from a script won't work. If you need to change the font dynamically, then you should only use the type I fonts in form fields, because they are always available. 

Another option is to create a copy of the form field with a different font, but in the exact same position. Then instead of changing the font, change the visibility of the fields.

Likes

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
Reply
Loading...
Jan 14, 2019 1
try67 LATEST
Most Valuable Participant ,
Jan 14, 2019

Copy link to clipboard

Copied

Or create a (hidden) field that uses that font and then save the file, causing the font to be fully embedded in the PDF.

Likes

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
Reply
Loading...
Jan 14, 2019 0
Most Valuable Participant ,
Jan 14, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Jan 14, 2019 0