Adobe PDF javascript : using the exportAsFDF function

It was very difficult to find and piece together all the pertinent information regarding how to incorporate the exportAsFDF() function with javascript code inside Adobe Acrobat Professional 6.0.  This step-by-step will alleviate a lot of your frustration and save your time!

In C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Javascripts\startup.js
include these two lines:  (since exportAsFDF function can only be called from menu, console, or batch. we’re using menu approach here)

app.addMenuItem({ cName: "ExportFDF", cParent: "File", cExec: "FDFExporting()", nPos: 0});
app.addMenuItem({ cName: "ForceFDFOverwrite", cParent: "File", cExec: "ForceFDFOverwrite()", nPos: 1});


Inside Adobe Acrobat 6.0 Professional’s menuItem: Advanced — Javascript — Document Javascripts:

function FDFExporting()

    var success_result = this.importDataObject("testingfile", this.getField("AuthNum").value + ".fdf");
// for some reasons, importDataObject() will put a file lock on the .fdf file.  There’s no way to unlock the file for overwriting unless you first close the application and re-open the file.

    if ( success_result ) {

            app.alert("Sorry, " + this.getField("AuthNum").value + ".fdf" + " already exists. Either delete this file first or use a different Auth Number.");


    else {
      this.exportAsFDF(true,true,null,false,this.getField("AuthNum").value + ".fdf",false);
      app.alert("Exported to a new file:   " + this.getField("AuthNum").value + ".fdf " );


function ForceFDFOverwrite()
            try {
                   this.exportAsFDF(true,true,null,false,this.getField("AuthNum").value + ".fdf",false);
                   app.alert("Successfully overwrote the file " + this.getField("AuthNum").value + ".fdf" );
            catch(e) {
                   app.alert("Could not overwrite " + this.getField("AuthNum").value + ".fdf due to file locking.  Please close this document and open it again to force an overwrite (without clicking on Export Button)." );


Using Advanced Editing Toolbar, add two buttons each that runs javascript:
Export Button:

Overwrite Button:

This entry was posted in Programming. Bookmark the permalink.