I want to get the internal PDF object number of the current font in use.

pdfTeX provides the primitive \pdffontobjnum which requires a font name as an argument. I have no clue what is expected as font name, e. g. something like cmr?

Whatever I try, I get a ! Missing font identifier. error.

For example:






So my question is, how to get a valid font name to be passed as an argument to \pdffontobjnum.


you can use \font to get the current font:







A font identifier is a control sequence corresponding to a font selection; it must be defined with the primitive \font (or \let to a control sequence so defined).

However, there are two predefined font identifiers. The first is \nullfont, which is not particularly useful because it has no characters. The second one is much more interesting and is \font itself.

Whenever TeX is looking for a font identifier, if it finds \font it will do as if you have used a font identifier corresponding to the current font.

In LaTeX the font identifiers are built in a standard format


so, for example, \OT1/cmr/m/n/10 refers to the default font. However, these identifiers are only built on demand when a \selectfont command is issued and points to the desired font; thus something like

\expandafter\pdffontobjnum\csname OT1/cmr/m/it/10\endcsname

might produce a Missing font identifier error, if the font hasn't yet been selected in the document. So you need to select the font before using \pdffontobjnum anyway.

The problem of identifiers only built on demand is not the main one. Consider the following plain TeX example:

\message{The font number is \tenitnumber}



This will cause a low level fatal error:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdftex)
 restricted \write18 enabled.
entering extended mode
ap} The font number is 1 [1]Assertion failed: (fo->last_char >= fo->first_char), function create_fontdictionary, file ../../../texk/web2c/pdftexdir/writefont.c, line 607.
 )Abort trap: 6

because the internal number points to an object that's apparently not created. No error if you add \it before \tenitnumber, so the font is actually used in the document. It's not sufficient to use the font in a box: indeed

\message{The font number is \tenitnumber}

\setbox0=\hbox{\tenit something}    


would fail in the same way. So you must typeset something in a font, if you want to store the object number corresponding to it.

The error doesn't happen with LuaTeX; for instance,

\edef\firstfont{\pdffeedback fontobjnum\tenit}


correctly prints 1 and pdffonts outputs

name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
SDXKYB+CMR10                         Type 1            yes yes no       5  0
  • Thank you for your explanations. This is what I expected, the font object is inserted into the PDF output and hence its object number is valid if only it has been used before by typesetting something. Finally I want to use the current text font within text fields in a PDF form, by adding the font object as a resource to the /AcroForm dictionary in the PDF Catalog. Unfortunately this did not work, producing a warning in AR and showing only dots in the TextField. But this might become another question here. – AlexG Jan 23 '18 at 14:11
  • @AlexG we're on the same quest for embedding LaTeX fonts (Type1) inside the /AcroForm? Do you have any insight or get it to work finally? – Fuhrmanator Sep 4 '18 at 2:04
  • @Fuhrmanator Results of my experimenting with fonts in PDF forms: tex.stackexchange.com/a/449681 – AlexG Sep 6 '18 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.