• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I need to extract form field names and all possible values.

New Here ,
Dec 12, 2024 Dec 12, 2024

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?

TOPICS
PDF forms

Views

182

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2024 Dec 12, 2024

Copy link to clipboard

Copied

What do you mean by "ALL of the possible options"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 12, 2024 Dec 12, 2024

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"). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2024 Dec 12, 2024

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";

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 12, 2024 Dec 12, 2024

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2024 Dec 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 12, 2024 Dec 12, 2024

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"]
    );
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2024 Dec 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2024 Dec 12, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2024 Dec 13, 2024

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

 

Capture_2412131023.png

 

It returns a row for each field and 45 columns of datas.

Capture_2412131129.png

 

* Requires the old UI, does not (yet) work with the new Acrobat experience.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2024 Dec 13, 2024

Copy link to clipboard

Copied

LATEST

Nice!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines