Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF forms with LaTeX: how to create \TextField of exactly 4in width?

I'm using PDFLaTeX to create forms and ran into a problem with the \TextField macro that defines input fields:

\TextField[width=4in,name=sample]{}

The resulting field is a little wider than 4 inches and I don't understand why. The following example illustrates the problem by resulting in an overfull hbox which gets highlighted because by an overfull rule.

\documentclass[a4paper,11pt]{article}
\usepackage[latin1]{inputenc} 
\usepackage[pdftex]{hyperref}

\overfullrule3pt

\begin{document}
\noindent \TextField[name=one, width=\hsize]{type here:}
\end{document}

The resulting PDF will show an overfull input field despite having specified exactly the available space as the desired width.

like image 218
Christian Lindig Avatar asked Oct 15 '10 18:10

Christian Lindig


1 Answers

The author of the hyperref package, Heiko Oberdiek, sent me an email and explained why the width is by default greater than specified. Each \TextField is passed through the following macro for layout:

\def\LayoutTextField#1#2{% label, field
   #1 #2%
}

Hence, we end up with the label, a space, and the input field. The width parameter only affects the input field. By re-defining the layout, we can ensure that we end up with the desired width as specified:

\def\LayoutTextField#1#2{#2}

This layout would simply drop the label ("type here:") to arrive at an input field of the desired width.

like image 164
Christian Lindig Avatar answered Sep 18 '22 15:09

Christian Lindig