6
Using Acrobat JavaScript in Forms
Filling in PDF Forms
The following example merges the data from several XML form attachments and submits it
to a server:
var oParent = event.target;
// Get the list of attachments:
var oDataObjects = oParent.dataObjects;
if (oDataObjects == null)
app.alert("This form has no attachments!");
else {
// Create the root node for the global submit:
var oSubmitData = oParent.xfa.dataSets.createNode(
"dataGroup",
"globalSubmitRootNode"
);
// Iterate through all the attachments:
var nChildren = oDataObjects.length;
for (var iChild = 0; iChild < nChildren; i++) {
// Open the next attachment:
var oNextChild = oParent.openDataObject(
oDataObjects[iChild].name
);
// Transfer its data to the XML collection:
oSubmitData.nodes.append(
oNextChild.xfa.data.nodes.item(0)
);
close the attachment//
oNextChild.closeDoc();
}
// Submit the XML data collection to the server
oParent.submitForm({
cURL: "http://theserver.com/cgi-bin/thescript.cgi",
cSubmitAs: "XML",
oXML: oSubmitData
});
}
116
Acrobat JavaScript Scripting Guide