I've been on the hunt for a code snippet that can retrieve values for specific fields in a PDF using JavaScript within Acrobat.
However, my goal is to capture all fields as key-value pairs in JavaScript. I did try some existing code, but unfortunately, it didn't yield the desired outcome.
if(this.hostContainer) {
var fieldValues = {};
fieldValues["personal.name"] = this.getField("personal.name").value.toString();
fieldValues["personal.loginname"] = this.getField("personal.loginname").value.toString();
try{
this.hostContainer.postMessage(fieldValues);
}
catch(error){
app.alert(error.message);
}
}
The structure of the PDF file appears as follows:
Name : x (editable)
Age : 36 (editable)
Sex : male (editable)
Note that the form fields within the PDF may vary.