8

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?

  • 1
    Is this for your use or others? Because most PDF viewers will either not support javascript or have it switched off as it is a security risk. Whether it works will be highly viewer-dependent and highly local-environment-dependent, too. – cfr Feb 1 '17 at 1:42
  • Predominantly my use. – BenB Feb 1 '17 at 19:05
4

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.
  • This doesn't work for me. The Javascript debuggers says the method is not allowed (NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode. Doc.exportAsText:1:Field ). – Ulrike Fischer Oct 6 '17 at 9:26
  • @UlrikeFischer I thought I had tested this with the free Adobe Reader as well, but I must be mistaken, as the API reference specifies that this functionality requires reader-enabling the PDF document first - I have edited the answer accordingly. In Adobe Reader, you could show the file instead of saving it using something like app.alert(this.exportAsTextStr()) (works for (X)FDF as well), possibly also in a text box so you can copy it to a file manually, but saving it directly doesn't seem to be an option. – diabonas Oct 6 '17 at 15:52
  • yes, with the pro-Version it works. And I do find it very useful, to have working examples for this type of things here ;-). – Ulrike Fischer Oct 6 '17 at 15:58
  • @UlrikeFischer Glad it works for you and you find it useful :) Figuring out stuff like this using the PDF and JavaScript API specification can be quite strenuous, so I am really great there are people like Heiko Oberdiek who already did much of the "heavy lifting" ;) – diabonas Oct 6 '17 at 16:10
  • @diabonas I expanded the PushButton onclick mailto action here tex.stackexchange.com/q/395117/13173 – Léo Léopold Hertz 준영 Oct 8 '17 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.