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'd like to create a LaTeX document that when rendered into PDF, has forms that can be filled out using Adobe Reader or other such programs. Then I'd like to be able to extract the data. I deliberately would like to avoid using Acrobat for all the usual reasons (non-free, need different versions for different platforms etc).

Can this be done ?

share|improve this question
1  
Creating a PDF form using pdflatex should be possible. However the "Then I'd like to be able to extract the data" part is then only a PDF issue. IIRC the PDF can be transmit the form to a web server. How exactly do you want to extract the data? –  Martin Scharrer Apr 3 '11 at 15:21
    
@Suresh Try this post tex.stackexchange.com/questions/7869/…, if this is what you are looking post a comment and I will add some explanations. Also search the JavaScript tag. –  Yiannis Lazarides Apr 3 '11 at 15:23
    
@Yiannis: that's an interesting trick. Makes me think though that I should give up on the latex and just use HTML + javascript. @Martin, even extracting to a text file would be fine. –  Suresh Apr 3 '11 at 15:27
    
@Suresh Best option would be in this case -- and I hate to say so to actually buy Acrobat Professional. It can do all these much easier transmit to the web collate the data etc... –  Yiannis Lazarides Apr 3 '11 at 15:33
    
@Yiannis that just makes me sad :) –  Suresh Apr 3 '11 at 15:49
show 2 more comments

3 Answers 3

up vote 52 down vote accepted

The hyperref package provides a method to create PDF forms. They way I understand it the form is either to be printed or to be transmitted to a webserver like a HTML form.

Here a small example:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\begin{Form}[action={http://your-web-server.com/path/receiveform.cgi}]
\begin{tabular}{l}
    \TextField{Name} \\\\
    \CheckBox[width=1em]{Check} \\\\
    \Submit{Submit}\\
\end{tabular}
\end{Form}


\end{document}

Gives:

Result

share|improve this answer
    
while both answers are great, this one is closer to what I need because it allows extraction of the data via a CGI script. –  Suresh Apr 3 '11 at 15:48
    
@Suresh: Give it a few hours (to see if there is another solution), then accept this one if it's still the best approach for you. –  Joseph Wright Apr 3 '11 at 15:51
    
yes, I was planning to wait a bit. I just wanted to clarify the things that were more important (extraction being one) –  Suresh Apr 3 '11 at 15:54
    
I've just created an example: martin-thoma.com/creating-pdf-forms-with-latex –  moose Mar 3 '12 at 6:35
add comment

I've used the eforms package, which is used by DANTE for their membership form (which of course I can't now locate in .tex format!). You'll probably have to download and unpack eforms from CTAN yourself, as it's not in TeX Live (unpack eforms, insdljs and taborder, all in the eforms bundle). A short example from a registration form I've done:

\documentclass{article}
\usepackage[pdftex]{eforms}

% From DANTE's registration form!

\newcounter{infoLineNum}
\setcounter{infoLineNum}{0}
\newcommand{\infoInput}[2][4in]{%
  \stepcounter{infoLineNum}%
  \makebox[0pt][l]{%
    \kern 4 pt
    \raisebox{.75ex}
      {\textField[\W0\BC{}\BG{}\TU{#2}]{name\theinfoLineNum}{#1}{12bp}}%
  }
    \dotfill
}

\begin{document}
\
\begin{tabular}{lp{4in}}
   Title                 & \infoInput{Title}\\[6pt]
   First name            & \infoInput{Firstname}\\[6pt]
   Last name             & \infoInput{Surname}\\[6pt]
   E-mail address        & \infoInput{Email}\\[6pt]
   Dietary requirements  & \infoInput{Dietary}\\[6pt]
\end{tabular}

\begin{tabular}{ll}
  Student (\pounds60) 
    & \raisebox{.75ex}{\radioButton{RegType}{10bp}{10bp}{Student}} 
      \\[6pt]
  Academic/post-doc (\pounds120)
    & \raisebox{.75ex}{\radioButton{RegType}{10bp}{10bp}{Academic}} 
      \\[6pt]
  Industrial (\pounds180)
    & \raisebox{.75ex}{\radioButton{RegType}{10bp}{10bp}{Industrial}} 
      \\[6pt]
\end{tabular}

\end{document}

This gives 'type in' boxes for the text areas and 'tick' boxes for the choices.

I'm not sure what happens about saving form data: according to Adobe Reader it can't be saved in this form. I've never actually seen a PDF form that can have the data saved, so whether even Acrobat can do this I do not know.

share|improve this answer
    
@Joseph Wright you need Acrobat professional to save the data, if I recall correctly, if you have it you can also enable the final copy of the pdf to be saved by those using the Reader alone. –  Yiannis Lazarides Apr 3 '11 at 15:36
    
Or, if you use a Mac, Preview allows you to save the data. –  Alan Munn Apr 3 '11 at 15:50
    
@Alan: I tried that, but it did not seem to work –  Joseph Wright Apr 3 '11 at 15:50
    
@Joseph I haven't tried the eforms package itself, but I routinely generate a syllabus for a course I supervise using hyperref's pdf forms methods, and if you fill in the form and then Save As in Preview, it saves the filled in form. –  Alan Munn Apr 3 '11 at 15:54
1  
@Joseph: In case you're still interested in retrieving the membership form in .tex format, it is actually attached to the application form itself. Like a first goodie for new members :) –  doncherry Apr 30 '11 at 11:41
show 4 more comments

Here is some code that I use to create forms that can be either printed and filled out with a pen or filled out electronically in a PDF viewer. When printed, the form provides a line for each form field. Like Martin Scharrer's solution I'm using the hyperref package. The tricky bit was to define an input field of a given length (here textwidth minus 4 cm). It required to override the \LayoutTextField hook.

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

\newdimen\longline
\longline=\textwidth\advance\longline-4cm

\def\LayoutTextField#1#2{#2} % override default in hyperref

\def\lbl#1{\hbox to 4cm{#1\dotfill\strut}}%
\def\labelline#1#2{\lbl{#1}\vbox{\hbox{\TextField[name=#1,width=#2]{\null}}\kern2pt\hrule}}

\def\q#1{\hbox to \hsize{\labelline{#1}{\longline}}\vskip1.4ex}

\begin{document}
  \begin{Form}
    \q{First Name}
    \q{Last Name}
    \q{Email}
   \end{Form}
 \end{document}

enter image description here

In a PDF viewer each line becomes a form field.

share|improve this answer
2  
To turn off red boxes: \def\labelline#1#2{\lbl{#1}\vbox{\hbox{\TextField[name=#1,width=#2,borderwidth=‌​0]{\null}}\kern0pt\hrule}}. –  Adobe Jul 8 '13 at 17:27
add comment

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.