These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to save the forms data in XML format with javascript?

aauricch
Registered: May 29 2007
Posts: 8

I am using Acrobat professional V 7.0 .
I like to write a javascript code which save the forms data as XML format into a file. Like when i use the menu File->Form Data->Export data from From...
Could you please send me an example of the javascript code ?
Thanks in advance.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
See the "exportXFAData" method for a full discussion of the security and Reader limitations of this method.

this.exportXFAData({
cPath: "/c/temp/myData.xml",
bXDP: false
})

George Kaiser

aauricch
Registered: May 29 2007
Posts: 8
With help of your answer the following solution runs successfully.

#################################################
I have created a Button with the following javascript code into the click event:
app.execMenuItem("SaveToLocalFile");

And I have create the file SaveDataToFile.js into the folder
C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Javascripts :

-- Content of SaveDataToFile.js ----------------------
// create a new menu item:
app.addMenuItem({
cName: "SaveToLocalFile",
cParent: "File",
cExec: "ExpDataXml();",
cEnable: "event.rc = (event.target != null);",
nPos: 1
});


function ExpDataXml()
{
this.exportXFAData({cPath: "/c/temp/myData.xml", bXDP: false});
};
---------------------------------------------------
################################################


To understand more the security of how Acrobat allow functions tu runs i have the following question:
Why I get the following error into the Console
TypeError: this.exportXFAData is not a function
1:XFA:form1[0].#subform[0].Button3[0]:click
when I replace app.execMenuItem("SaveToLocalFile");
with this.ExpDataXml(); in the click event of the button ?
I will appreciate if you have a workaround to bypass this problem.
Thanks in advance for your help.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
LiveCycle Designer designed forms are different from Acrobat designed forms, especially at the JavaScript extensions. With LiveCycle Designer you can use:

xfa.host.exportData("filename.xml", 0);

See LiveCycle Designer "Help => Scripting" for more information.,

George Kaiser