Copy link to clipboard
Copied
I have fillable PDFs for a project. But through piloting, we made changes to the forms. To make sense of the data, I need to compare all of the fields and their related response options (I have several drop-down fields) across all versions of the form. I have lots of versions, so comparing one form to the next manually is going to take forever. I've tried using python to extract all of this, but I can't seem to get it to work the way I need it to. I know how to extract data from the form, or extract the field names by merging to an Excel file. I don't just need the option that's selected in the form, I need ALL of the possible options. I feel like this should be a built-in tool. Can anyone help, please?
Copy link to clipboard
Copied
What do you mean by "ALL of the possible options"?
Copy link to clipboard
Copied
I mean, if I have a drop down menu that has ten response options, then in the file I'm trying to create, I need to know what all ten possible options are, not just the first option (which in my forms is "Select").
Copy link to clipboard
Copied
Use this function:
function DDItems(dd)
{
if(dd.type=="combobox")
{
var options="";
for(var i=0;i<dd.numItems;i++)
{
options+=dd.getItemAt(i,false)+"\n";
}
return options
}
}
Assuming the field is called "Dropdown", call the function like this:
DDItems(this.getField("Dropdown"))
The false in dd.getItemAt(i,false) means there are no separate export values. If there are and you want the display names and the export values you would change that line to something like:
options+=dd.getItemAt(i,false)+":"+dd.getItemAt(i,true)+"\n";
Copy link to clipboard
Copied
This is returning:
Syntax Error: syntax error
1: Console: Exec
undefined
I've tried optimizing, I've asked it for a simple return of the number of fields (118)... I'm lost.
Copy link to clipboard
Copied
Number of fields is this.numFields
Copy both of my scripts into the console, select all of it, and run it. There shouldn't be a syntax error.
Copy link to clipboard
Copied
Ok, thank you! I was missing the "select all of it" part. That's why I kept getting errors. Silly me, I know - but I am not a coder. I was just pasting and pressing enter - which worked fine with one liner test code.
Once I got that figured out, here's what I was looking for. This returned comma separated values for each field, with the field title, type of field, and any response options, so I can toss them into a spreadsheet as a codebook. Now I can do this for each version, and compare.
Thanks for your help!
// Script to extract form field information in a table format
var fieldData = [];
for (var i = 0; i < this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
var field = this.getField(fieldName);
var fieldInfo = {
"Field Name": fieldName,
"Field Type": field.type,
"Dropdown Options": "",
"Radio Button Options": ""
};
if (field.type === "combobox") {
var dropdownOptions = [];
for (var j = 0; j < field.numItems; j++) {
dropdownOptions.push(field.getItemAt(j, false));
}
fieldInfo["Dropdown Options"] = dropdownOptions.join(", ");
}
if (field.type === "radiobutton") {
var radioOptions = [];
var buttons = field.getArray();
for (var k = 0; k < buttons.length; k++) {
radioOptions.push(buttons[k].value);
}
fieldInfo["Radio Button Options"] = radioOptions.join(", ");
}
fieldData.push(fieldInfo);
}
console.println("Field Name, Field Type, Dropdown Options, Radio Button Options");
for (var i = 0; i < fieldData.length; i++) {
console.println(
fieldData[i]["Field Name"] + ", " +
fieldData[i]["Field Type"] + ", " +
fieldData[i]["Dropdown Options"] + ", " +
fieldData[i]["Radio Button Options"]
);
}
Copy link to clipboard
Copied
Whenever I mention running a script in the console I usually link to this:
https://pdfautomationstation.substack.com/p/the-javascript-console
You can also create the Excel spreadsheet by writing a string with tabs and new lines, then passing the string to a data object that you create with the .xls extension. The result shows up as an Excel attachment in the PDF.
Copy link to clipboard
Copied
I can write the script for you for a fee. If you are interested please send me a private message by clicking the icon in my profile.
Copy link to clipboard
Copied
The FORMREPORT plugin which is part of the (free) abracadabraTools* was made for you.
Enjoy: https://www.abracadabrapdf.net/?p=972
It returns a row for each field and 45 columns of datas.
* Requires the old UI, does not (yet) work with the new Acrobat experience.
Copy link to clipboard
Copied
Nice!