简体   繁体   中英

Export PDF form data to XML using Javascript

I made an interactive PDF with InDesign contain some textfields and a button. When this button is pushed I want it to extract the values from the textfields and put these into an XML file. So what this button has to do is call the action "Export form data" with as file extension *.xml. I thought this can be done using javascript (within the actions tab in the properties of the button), but I can't seem to find it.

I have Adobe acrobat Pro 10 and I work on a mac.

I already tried following codes:

this.saveAs("../Test.xml" , "com.adobe.acrobat.xml-1-00");

and

var name = getField("name").value;
var jobId = getField("jobId ").value;
var fieldsToSubmit = ['name', 'jobId'];

this.submitForm
({
               aFields: fieldsToSubmit,
               cSubmitAs: 'XML',
               cPath: "../"
});

This last one works if I use cURL instead of cPath with an email address defined. But this isn't really what I need. The XML file should be submitted to an local storage for example "/users/MyDocuments/Folder/filename.xml".

Can someone please tell me what I'm doing wrong ? Or is this impossible ?

Kind regards

Michiel

As you want to write the exported data file to the file system (instead of submitting to a service), submitForm() is not really suitable.

The closest coming to my mind would be exporting as XFDF. XFDF is an XML representation of FDF, the PDF native forms data format. XFDF can then easily be transformed to what you need.

Another approach would be creating the XML file content and write it into a Data Object, which then can be exported.

The latter would get an immediately usable result, but would require more programming.

For both methods, it is strongly suggested to consult the Acrobat JavaScript documentation, which is part of the Acrobat SDK, downloadable from the Adobe website.

Woo-hoo! I found it!

var url = "mailto:testemail@qoppa.com?subject=My Subject&body=Here is my form data.";
this.submitForm({cURL: url, cSubmitAs: "XFDF"})

I modified a solution that was provided for "XFDF":

https://kbpdfstudio.qoppa.com/send-email-with-pdf-form-data-using-javascript-submitform/

All I did was swap "XDFL" for "XML."
JavaScript magic!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM