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

1

7

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 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.

Keavy answered 15/10, 2010 at 18:7 Comment(0)
K
7

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.

Keavy answered 19/10, 2010 at 19:57 Comment(3)
I had been using an \hspace{-8.5pt} as a label for 10pt fonts to adjust horizontal position, but this method is a lot cleaner.Lakin
Can't you just supply an empty label each time with equivalent result?Mariken
Would you not still get the space?Keavy

© 2022 - 2024 — McMap. All rights reserved.