# eforms using a LaTeX (custom) font for text fields \textFont

I'm unable to use a LaTeX font (e.g., Augie) for text fields in a PDF form generated with eforms. I'm using MikTeX 2.9 on Windows 10. Acrobat Reader is choosing another font to display in its place (looks like MyriadPro-Regular, which seems to be what Adobe Reader substitutes for missing fonts):

The LaTeX font is fully embedded as "Augie" according to Adobe Reader's Properties:

Also, according to pdffonts:

pdffonts embedViaPS.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
[none]                               Type 3            Custom           yes no  no      27  0
Augie                                Type 1C           WinAnsi          yes no  no      24  0
ZapfDingbats                         Type 1C           Custom           yes no  yes     13  0
Helvetica                            Type 1C           WinAnsi          yes no  no      17  0


It's my understanding that for a font to be used in a field, it must be fully embedded (as opposed to an embedded subset). I am achieving this using -j0 on dvips and a customized ps2pdf by way of GhostScript. Here's the (redacted) output from TeXstudio showing all the commands:

latex.exe -src -interaction=nonstopmode embedViaPS.tex

dvips.exe -j0 -o embedViaPS.ps embedViaPS.dvi

' TeX output 2018.08.31:1642' -> embedViaPS.ps
<C:\MikTeXPortable\texmfs/data\fonts\pk\ljfour\jknappen\ec\dpi600\ecrm1000.pk>
<C:/MikTeXPortable/texmfs/install/dvips/base/tex.pro>
<C:/MikTeXPortable/texmfs/install/fonts/enc/dvips/base/8r.enc>
<C:/MikTeXPortable/texmfs/install/dvips/base/texps.pro>
<C:/MikTeXPortable/texmfs/install/dvips/base/special.pro>.
<C:/MikTeXPortable/texmfs/install/fonts/type1/emerald/faumw.pfb>

[1]
Process exited normally

"C:\Program Files\gs\gs9.10\bin\gswin64c.exe" -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -dSubsetFonts=false -sOutputFile="C:\hiddenpath\embedViaPS.pdf" -f "C:\hiddenpath\embedViaPS.ps"

Process exited normally

Process exited normally


I've done some debugging using the MWE below:

\documentclass{article}
\usepackage[dvips]{eforms}
\usepackage{emerald}
\usepackage[T1]{fontenc}
\begin{document}
\everyTextField{
\BC{1 0 0} % border color
\BG{.941 1 .941} % background color
\textColor{0 0 1} % is black
\AA{\AAFormat{console.println("Font set to: '" + event.target.textFont + "', trying to set it to: '" + event.target.value + "'"); event.target.textFont = event.target.value;}}
\textSize{10}
\Ff{\FfDoNotScroll}
}

% Content containing form fields, such as...
{\ECFAugie
\textField[\textFont{Augie}]{name}{1.5in}{12bp}
\end{document}


Upon opening in Adobe Reader DC the PDF generated from this document, I see in the JavaScript console (enabled in Preferences) the following output:

Font set to: 'Augie', trying to set it to: ''


I'm using Augie as the name, since that is what's showing up in pdffonts and the properties of Adobe Reader. However, even though I have initialized the \textField with that font (from the output), it's not displaying that font in Adobe Reader DC. Furthermore, if I try to reset it to Augie using the form field (typing Augie and pressing enter), I get the following:

Font set to: 'Augie', trying to set it to: 'Augie'

InvalidSetError: Set not possible, invalid or unknown.
Field.textFont:2:Field name:Format


The script allows me to type a font name into the field and when I press enter, it attempts to set the font of that field using JavaScript. I'm able to set the field to other values, e.g., Helv, Helvetica, Another, Bauhaus93, etc. (the last two are installed on my Windows machine as TrueType fonts).

I don't want (or rather can't) use XeTeX as it seems there's no way to fully embed fonts into the PDF.

• Is there perhaps another name for the font than Augie?
• Is there perhaps some other detail for the font that's not right, e.g. it's not editable according to its fsType/FSType? Can I even control that in LaTeX? Edit As a test, I hacked the Augie font (faumw.pfb) using FontForge and set its fsType to 8 - editable embedding, but nothing changed.
• I have not yet tried to install a TrueType (OpenType) font in MikTeX because it's a long process, but perhaps that will yield a better result?
• I discovered that the fonts have to be in the PDF structure at Acroform / DR / Font (and using brendandahl.github.io/pdf.js.utils/browser I confirmed that Augie is not there). A solution might be to get eforms to do that. – Fuhrmanator Sep 3 '18 at 18:23
• The font resource has to be in the Acroform resources (as above). Using hints from stackoverflow.com/a/30248927/1168342 I was able to "fix" a PDF as a separate step at the end (just by using pdflatex). I did it with a TTF but as yet have not tried Type1... As much as I'd like this to be 100% LaTeX solution, I don't think it's possible with existing tools. eForms doesn't appear to support embedding fonts into the Acroform of a PDF. – Fuhrmanator Sep 5 '18 at 21:30

In theory, acc. to the PDF specification, any embedded document font can also be used in interactive PDF forms, such as text input fields. For this to work, the font must be properly registered in the /AcroForm dictionary of the document's PDF Catalog.

Here is a LaTeX example, using the standard CM Font (PostScript Type 1) in various combinations of style, size and colour:

# Evince

Also, Foxit Reader properly displays the font.

Alas,

fails to display the embedded T1 font, which is a bug, most likely. It seems that AR digests only TrueType fonts correctly.

In order to produce the PDF shown, the standard packages for creating PDF Forms, hyperref and eforms, cannot be used as they fail to register the embedded fonts for use in forms. Instead, we re-implement a \textField command based on the file pdfbase.sty. It provides \pbs_add_form_font: which maps the current text font object as a font resource in the /AcroForm dictionary. In order to get access to the font object, \pbs_add_form_font: makes use of the pdftex built-in \pdffontobjnum. The example below can therefore be processed only with pdflatex or lualatex.

\documentclass{article}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Text Input Field
% \textField{<name>}{<width>}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pdfbase,xcolor}
\makeatletter
\ExplSyntaxOn
\newcommand{\textField}[2]{
% register current font in /AcroForm <<...>> PDF dictionary
% get current text colour
\extractcolorspec{.}\@tempb
\expandafter\convertcolorspec\@tempb{rgb}\@tempb
\edef\@tempa{\expandafter\@rgbcomp\@tempb\@nil}
% insert Text Field
\raisebox{0.4\depth}{\makebox[#2][l]{
\pbs_pdfannot:nnnn{#2}{\ht\strutbox}{\dp\strutbox}{
/Subtype/Widget/FT/Tx/T (#1)
% set font, size, current colour
/DA (\pbs_last_form_font:\space\f@size\space Tf~\@tempa\space rg)
/MK<</BC [0~0~0]/BG [0.9~0.9~0.9]>>
}\strut
}}
% register Text Field in /AcroForm
\pbs_appendtofields:n{\pbs_pdflastann:}
}
\ExplSyntaxOff
\def\@rgbcomp#1,#2,#3\@nil{#1 #2 #3} %helper
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set of characters of the current font to be embedded
\usepackage{luatex85}
\newcommand{\embedChars}[1]{\pdfincludechars\font{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\parindent=0pt

\begin{document}
%\normalfont%
\embedChars{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- /}%
First Name: \textField{myFName1}{0.4\linewidth}\\
Last Name: \textField{myLName1}{0.4\linewidth}\\
Date of Birth: \textField{myBDate1}{0.2\linewidth}\\

\scshape\Large\color{red}%
\embedChars{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- /}%
First Name: \textField{myFName2}{0.4\linewidth}\\
Last Name: \textField{myLName2}{0.4\linewidth}\\
Date of Birth: \textField{myBDate2}{0.3\linewidth}\\

\huge\itshape\color{blue}%
\embedChars{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- /}%
First Name: \textField{myFName3}{0.4\linewidth}\\
Last Name: \textField{myLName3}{0.4\linewidth}\\
Date of Birth: \textField{myBDate3}{0.6\linewidth}\\

\end{document}

• Thanks for posting this. I looked at the PDF and all of the Type1 fonts have embedded subsets. My understanding was that the fonts have to be fully embedded for Adobe Reader to work (Adobe Reader is displaying dots, meaning the character isn't mapped?). I'm not familiar at all with pdftex, but is there a way to force the Type1 fonts to be fully embedded, just to try? Just use all characters in \embedChars? Otherwise, I could try hacking something with my PDFBox code to fully embed those fonts on a PDF to see if it works. – Fuhrmanator Sep 6 '18 at 20:05
• Following tex.stackexchange.com/a/24005 I managed to embed fully the fonts using a .map file per the pdftex documentation. Alas, Acrobat Reader still doesn't manage. – Fuhrmanator Sep 6 '18 at 23:29
• Then, I would call it an AR bug. – AlexG Sep 7 '18 at 6:37
• I got AR to work using a font map with proper flags. It's all documented under pdftex: 6. Setting up fonts. As a MWE, 1) create a file fullembed.map with one line cmr10 CMR10 34 <<cmr10.pfb, 2) insert in your example above before begin{document} the line \pdfmapfile{=fullembed.map}. The flags 34 is important (in my comment above I didn't use it). It's 32 (Uses the Adobe Standard Roman Character Set) + 2 (Serif font) from the flags in Table 3. Only the first fields work, as the other fonts aren't in the map (MWE). – Fuhrmanator Sep 7 '18 at 15:09
• No more dots in the textfields. But it is definitely not Computer Modern Roman (CMR10), rather some replacement. – AlexG Sep 7 '18 at 15:58