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

What is the script I can use to change the font in a textfieldin

Participant ,
Apr 14, 2021 Apr 14, 2021

Hi everyone, I would like to change the font in  a text field.

It´s not a global change. It would affect only a specific group of text fields in a given

page.

 

I found the script: this.getField("Textfield").textFont = "Font name"

 

but it is not working. Please let me know if I´m doing anything wrong.

Thanks a lot!!

TOPICS
Create PDFs , How to , JavaScript , PDF forms
687
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 15, 2021 Apr 15, 2021

The code seems fine. The tricky part is knowing the actual internal name of the font you want to use, as you can't just use the name that appears in the font selection list.

The best way of finding out that name is by manually assigning this font to a field (let's say it's called "Text1") and then running this code from the JS Console:

 

this.getField("Text1").textFont;

 

It will print out the internal name of that font, and you can then use that in your real script to apply it to other fields in the file.

View solution in original post

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 ,
Apr 14, 2021 Apr 14, 2021

You may want to share the exact script thatis not working for your or an example of that PDF in order to get better assistance.

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 ,
Apr 14, 2021 Apr 14, 2021

What happens when you use the script? Any error in the Javascript console?

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 ,
Apr 15, 2021 Apr 15, 2021

The code seems fine. The tricky part is knowing the actual internal name of the font you want to use, as you can't just use the name that appears in the font selection list.

The best way of finding out that name is by manually assigning this font to a field (let's say it's called "Text1") and then running this code from the JS Console:

 

this.getField("Text1").textFont;

 

It will print out the internal name of that font, and you can then use that in your real script to apply it to other fields in the file.

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
Participant ,
Apr 15, 2021 Apr 15, 2021
LATEST

Thanks a lot for yor tip and advice!

 

The problem was: My desired font´s name has two words. Using your method, I found out that

it is actually written as one word. Now, everything worked perfectly!!

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