# hyperref: how to format text in a forms text-field

I would like to pre-format the text in a form text-field, e.g. make it bold, italic or use a specific font. The following code generates a simple text-field:

\documentclass{scrreprt}
\usepackage{hyperref}
\begin{document}
\textbf{The Text Field}
\begin{Form}
\TextField[]{\ }
\end{Form}
\end{document}


Is it possible to pre-format the text in the text-field? The hyperref package manual (10/2011) speaks of an optional parameter format and the use of JavaScript to format the field. Can this be used to format the text in the field? And if yes, how is it done? (I am not proficient in JavaScript)

-
See the JavaScript™ for Acrobat® API Reference, p. 444 and surroundings for an overview of JavaScript in PDF formatting stuff. –  doncherry Feb 26 at 14:53
Stephan Lehmke: which fonts? Normally, pdfTeX does not embed complete fonts. Instead, it embeds subsets which contain the characters needed to display the content. Not only does this mean there is no guarantee a particular character is included in a subsetted font. These fonts also have weird (possibly unpredictable?) names. You can tell pdfTeX to embed complete fonts although this will obviously increase the file size. Is your question how to do that and how to use those fonts to format the text fields? –  cfr Sep 24 at 21:24
@cfr Exactly. Obviously, a font would need to be completely embedded to be used in a form field. Answers in Adobe forums tell that much. I know how to get pdftex to completely embed a font. Alas, so far no success to actually get that font to be used in a form field. Maybe an encoding problem? So the question really is how to use an embedded font in a Text Field reliably. –  Stephan Lehmke Sep 27 at 8:57
btw, the application I'm thinking about is producing "advertisement sheets" as preformatted PDF where only the "price tag" needs to be typed in before printing. –  Stephan Lehmke Sep 27 at 9:00
How exactly are you getting the font embedded and which font(s)? I doubt that Acrobat could use metafont or virtual fonts, for example. –  cfr Sep 28 at 1:01

I want to provide an example that shows most of the possibilities. I hope it helps:

\documentclass{article}
\usepackage[pdfstartview=FitH]{hyperref}

\begin{document}

\begin{Form}

\TextField[name = number.1,
format = {
var f = this.getField('number.1');
f.textFont = 'Verdana';
f.strokeColor = ['T'];
f.fillColor = ['T'];
f.userName = 'first number'
},
value = 1250,
charsize = 10pt]
{number 1}

\TextField[name = number.2,
format = {
var f = this.getField('number.2');
f.textFont = 'Verdana';
f.strokeColor = ['T'];
f.fillColor = ['T'];
f.userName = 'second number'
},
value = 500,
charsize = 10pt]
{number 2}

\TextField[name = sum,
format = {
var f = this.getField('sum');
f.textFont = 'Verdana';
f.strokeColor = ['T'];
f.fillColor = ['T'];
},
calculate = {
this.getField('sum').value =
this.getField('number.1').value + this.getField('number.2').value;
},
charsize = 10pt,