[Tex/LaTex] hyperref: how to format text in a forms text-field

formattingformshyperrefjavascript

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)

Best Answer

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'];
               f.userName = 'sum'
               },
           calculate = {
               this.getField('sum').value =
                 this.getField('number.1').value + this.getField('number.2').value;
               },
           charsize = 10pt,
           readonly = true]
          {sum}

\end{Form}

\end{document}

This example was adapted from a German community.