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

-
add comment

## 1 Answer

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

\listfiles
\documentclass{article}
\usepackage[pdfpagemode=None,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}


The example was shown in a German community:

-
Thanks for the link. Do you have a solution for using TeX-fonts (embedded into the pdf-file) instead of system fonds? –  Rainer Jan 8 '12 at 11:36
I would ask such a question at de.comp.text.tex. Heiko Oberdiek is very active there. (Maybe he will register here). You should link to this question here. –  Marco Daniel Jan 8 '12 at 11:47
add comment