[Tex/LaTex] Save PDF form information

formshyperref

I'm building a form using the Hyperref package. I would like to be able to save the information filled into the form.

Currently, I can have it automatically open an email client with attached information:

\documentclass{article}
\RequirePackage{hyperref}
\begin{document}
\begin{Form}[action=mailto:test@testnet.com,encoding=html, method=post]
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\Submit{Submit}
\end{Form}
\end{document}

According to this, I should be able to save a form locally using:

\documentclass{article}
\RequirePackage{hyperref}
\begin{document}
\begin{Form}[action=my_form_response.doc,encoding=html, method=get]
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\Submit{Submit}
\end{Form}
\end{document}

However, when I click the submit button, I get the error "Error opening URL to submit form".

Question: Can I have the form data save locally? How?

Best Answer

The action parameter can only be used to send the filled-out form to a server (by specifying the URL to a CGI script) or by email (by specifying the email prefixed with mailto:, as demonstrated in your first example). To save the data to a file, you need to use a button with a custom JavaScript action instead:

\documentclass{article}
\RequirePackage{hyperref}
\begin{document}
\begin{Form}
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\PushButton[onclick={this.exportAsText()}]{Submit}
\end{Form}
\end{document}

In this way, the form data will converted to CSV format and the user will be prompted to save the resulting file to disk. Note that this requires the paid version of Adobe Acrobat, the free Adobe Reader doesn't have this functionality enabled (unless activated using Adobe Experience Manager Forms).

Other possible output formats can be achieved by changing exportAsText in the above example to one of the following:

  • exportAsFDF saves the data in Adobe Forms Data Format, a simpler version of the PDF format. This can be useful if you want to process the data further using Adobe software.
  • exportAsXFDF uses the Adobe XML Forms Data Format, which can be further processed by Adobe software as well as all XML parsers.