Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
    
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

1 Answer 1

up vote 9 down vote accepted

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.