Assume you have the following form in PDF ouput/equivalent in Fig. 1.
I am thinking how to design the LaTeX form well enough for good data extraction (and eventually seeding into PostgreSQL database).
You want to extract the following pieces of data in the form:
- Question 1 answer
- Question 2 answer
- Summary result
Code to generate the PDF file
% https://tex.stackexchange.com/a/384801/13173
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\begin{enumerate}
\item \ChoiceMenu[name=football,radio,default=0]{Do you play football?}{Much (2)=2,Little (1)=1,Not at all (0)=0}
\item \ChoiceMenu[name=ice-hockey,radio,default=0]{Do you play ice-hockey?}{Much (2)=2,Little (1)=1,Not at all (0)=0}
\end{enumerate}
\TextField[readonly=true,value=0,calculate={event.value=this.getField("football").value+this.getField("ice-hockey").value;}]{Summary score:}
\end{Form}
\end{document}
Fig. 1 Output
Testing accsupp [rejected because cannot take user input] (Steven)
Code which is not good example because it has integrated values and is not taking values from the user;
\documentclass{beamer}
\usepackage[english]{babel}
\usetheme{Berkeley}
\usepackage{accsupp} % https://ctan.org/pkg/accsupp
\begin{document}
\begin{frame}
\frametitle{Field}
\section{Field 2}
\begin{equation}
\BeginAccSupp{
method=pdfstringdef,
unicode,
ActualText={%
a\texttwosuperior +b\texttwosuperior
=c\texttwosuperior
}
}
a^2 + b^2 = c^2
\EndAccSupp{}
\end{equation}
\end{frame}
\end{document}
Output in Fig. 2 where I do not really see the point of this package with user inputs, since it is not asking them in the form.
Fig. 2 Output of too simple basic example of accsupp
OS: Debian 9
TeXLive: 2017
Best Answer
As described in Save fillable forms, you can create forms that send their values back to you by email if you click the submit button:
If you click the Submit button, an email to the provided address (here
forms@stackexchange.invalid
) will be composed in your default email program with an attached.fdf
file. This attachment contains the submitted data as XML:The XML file generated by Adobe Acrobat (Reader) looks a bit peculiar, but can be further processed by any XML parser. Other possible output formats for the
.fdf
file, specified by theexport
option of the submit button, are:export=html
: exports the data in query string syntax.export=fdf
: uses Adobes own Forms Data Format, basically a simplified version of the PDF file format, which might be useful if you want to process the data further using Adobe software.export=pdf
: attaches the whole, filled-out PDF file to the email, which you can then process as described in the second part of this answer.As an alternative, you could consider using the open source PDFtk to extract data from a saved filled-out PDF document: running
on a filled-out document
document.pdf
will report something like