Copy link to clipboard
Copied
The code below lists all the field names in a PDF. However, it does so in alphabetical order. I would like to be able to get these into Excel, but in the order they appear through the PDF form itself.
Side question, whats the save as file option here - excel or csv?
Thanks all.
console.show();
console.clear();
console.println("Number of fields: " + this.numFields);
for(var i = 0; i < this.numFields; i++)
{
console.println(this.getNthFieldName(i));
}
Copy link to clipboard
Copied
This requires some advanced scripting.
Listing the fields in the order they appear in the PDF means analyzing the field locations (i.e. page number and rectangle). Some fields may have multiple locations, so the sorting will need to take that into account.
To do this, collect all the fields into an array and sort the array according to the field's geometry.
Here's an outline for the code, note that the sorting function is missing.
var aFlds = [];
for(var i = 0; i < this.numFields; i++)
aFlds .push(this.getField(this.getNthFieldName(i)));
var aFieldNames = aFlds.sort(function(oFld1,oFld2){...}).map(oFld=>oFld.name);
console.println(aFieldNames.join("\n"));
An Acrobat script cannot write anything but a PDF directly to the users file system. It can however create an attachment to the PDF and then force that attachment to open.
In this case the script should create a csv file. Most computers will open this file type in Acrobat.
Use the "doc.createDataObject()" function
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#createdataobject
Then use the "doc.openDataObject()" to force the attachment to open in Excel.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#opendataobject
Copy link to clipboard
Copied
Sorry for the delayed response! I found your reply in my junk folder. Thanks for the info and ideas. It's probably going to be outside my wheelhouse, but I will investigate. I'm satrting with sort functions.
Copy link to clipboard
Copied
Is it possible with the basic console script I posted to send the results to clip board, or txt file?
Copy link to clipboard
Copied
You can select and copy the content of the console.