Skip to main content
M.Hasanin
Inspiring
November 23, 2017
Answered

inherit field font from another field with JavaScript

  • November 23, 2017
  • 1 reply
  • 740 views

Hi,

Please i want to know if there a way to inherit field font from another field (in Acrobat Pro DC) .. not just setting the font to the field, because i have full embedded font inside my form in Other language than english (Arabic) and i want the english text field to inherit font from another field  (Ar --> En) or Vise Versa, so the statment :

this.getField("GenManagerAr").textFont

maybe is not the perfect one to use!, any tips please ? thanks in advance

This topic has been closed for replies.
Correct answer Thom Parker

Field fonts are always fully embedded (unless it is a type I font). Because any text could be placed in the field, the whole font is needed.  If you set another field to the same font, Acrobat will reference the font object for the first field. So for fields you never get duplicate font objects.

The line of code below copies a reference for the font in "text1" into "text2", it does not duplicate the font.

getField("Result2").textFont = getField("Result1").textFont;

However, fonts for page text are handled differently from field fonts. First, they are almost always embedded subsets, not full font definitions. There is also a possible difference in how the character codes are handled between fields and content. Fields typically use 1 byte codes, whereas content is often 2 byte character codes.  For these reasons Acrobat doesn't mix Field fonts and Content fonts.

That said, there is no reason why you couldn't write your own plug-in that modifies the fonts so that both content and fields share the same font definition.  In fact, it's possible that applications from Quite, Callas, or some other print oriented tool vendor already do this.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 23, 2017

Field fonts are always fully embedded (unless it is a type I font). Because any text could be placed in the field, the whole font is needed.  If you set another field to the same font, Acrobat will reference the font object for the first field. So for fields you never get duplicate font objects.

The line of code below copies a reference for the font in "text1" into "text2", it does not duplicate the font.

getField("Result2").textFont = getField("Result1").textFont;

However, fonts for page text are handled differently from field fonts. First, they are almost always embedded subsets, not full font definitions. There is also a possible difference in how the character codes are handled between fields and content. Fields typically use 1 byte codes, whereas content is often 2 byte character codes.  For these reasons Acrobat doesn't mix Field fonts and Content fonts.

That said, there is no reason why you couldn't write your own plug-in that modifies the fonts so that both content and fields share the same font definition.  In fact, it's possible that applications from Quite, Callas, or some other print oriented tool vendor already do this.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
M.Hasanin
M.HasaninAuthor
Inspiring
November 23, 2017

Thank you very much for your valuable information's!

Mohammad Hasanin