[Tex/LaTex] eforms using a LaTeX (custom) font for text fields \textFont

dvipsfontsformspdf

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):

enter image description here

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

enter image description here

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

This is dvips(k) 5.998 Copyright 2018 Radical Eye Software (www.radicaleye.com)

' 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 started: "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "C:\hiddenpath\embedViaPS.pdf"

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
Your name: }
\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).

enter image description here

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?

Best Answer

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

enter image description here Also, Foxit Reader properly displays the font.

Alas,

Acrobat Reader

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

enter image description here

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
    \pbs_add_form_font:
    % 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}