• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Retrieving Data from an Adobe Acrobat Document

Hi,

One of our clients recently sent out a Survey in the form of an adobe acrobat form that allowed participants to enter information into the form.

The survey participants then filled out the pdf document, saved it, and emailed it to us.

How can we extract the data from the .pdf into our database?

I have uploaded a blank example of this survey here: http://www.braynard.com/survey.pdf. Thanks.
0
Frylock
Asked:
Frylock
  • 13
  • 5
1 Solution
 
Karl Heinz KremerCommented:
Do you have the full version of Acrobat? If so, you have (at least) two different ways to do this: You can either use JavaScript in Acrobat to create a small program that extracts the data and then uses ADBC (which is Adobe's JavaScript wrapper for access to ODBC data sources) to write this information into the database (this does however not work on a Mac), or you can use a VB program that uses Acrobat's API to access this information and write it to the DB.
Let me know which method you prefer, and I can provide some code. Keep in mind however that I'm not programming in VB, but I can give you the commands that are necessary to access the data, I'm more familiar with JavaScript.
0
 
FrylockAuthor Commented:
The first option works - we have acrobat pro.
0
 
FrylockAuthor Commented:
Ah - new problem. I found advanced>forms>export data.

It exports into some lousy txt file or an XML file. Question is, can I take that xml and put it into a dbf through some automated process? SQL Server and Foxpro don't seem to allow import of an XML.
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
Karl Heinz KremerCommented:
No, not a new problem. You don't need the FDF or XFDF files (and not, these are not lousy formats, they have their place, and for some workflows they are important).

Create a file in Acorbat's JavaScript directory (usually C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Javascripts) with an extension .js, and the following content (name the file e.g. submit_data.js):

function addToDatabase()
{
    try
    {
        var con = ADBC.newConnection("test");

        var statement = con.newStatement();
        if (statement == null)
        {
            throw("Cannot create new statment");
        }

        // get data from the active document
        var f1 = this.getField("Field1");
        var f2 = this.getField("Field2");
        var f3 = this.getField("Field3");

        // create the SQL query string
        var q = "INSERT INTO myTable (`Field1`, `Field2`, `Field3`) VALUES('" +
            f1.value + "','" + f2.value + "','" + f3.value + "')";

        statement.execute(q);

        con.close();
    }
    catch (e)
    {
        console.println("Error: " + e);
    }
}


app.addMenuItem({
    cName: "Fill Database",
    cParent: "Document",
    cExec: "addToDatabase();",
    cEnable: "event.rc = (event.target != null);",
    nPos: 0
});

Replace the "test" in the newConnection() call with your data source name. Adjust the SQL command and change the field names (you can of course add more fields).
This will add a new menu item under the "Documents" menu that will extract the data from the current document and insert the data into the database.
0
 
FrylockAuthor Commented:
How do I know what the field names are? Can you take a look a tthe document I uploaded? Thanks for your help.
0
 
FrylockAuthor Commented:
Also, I added the .js file to the directory (slightly different from the one you spelled out: "C:\Program Files\Adobe\Acrobat 7.0\reader\Javascripts\db1.js"

And it does not show up under 'Documents.'
0
 
FrylockAuthor Commented:
btw- I fixed the last problem (Put it in the 6.0 folder) but I cannot get it to show up i ndocuments.
0
 
Karl Heinz KremerCommented:
Open up the JavaScript console (Ctrl-J). Do you see any error messages after you start Acrobat?

When you open your document in Acrobat, and select the Select Object Tool (on the Advanced Editing toolbar), you will see all the form field names. On your first page, you'll see for example "State", "Date", "Responding Official", "Title", "Address", "Email", "Phone", Fax Number" and so on.
0
 
FrylockAuthor Commented:
CTRL-J doesn't show anything.

See here: http://www.braynard.com/adobe.JPG
0
 
Karl Heinz KremerCommented:
Where exactly did you place the script?
0
 
FrylockAuthor Commented:
C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Javascripts

It's called "db1.js" and there are other scripts also in that directory. Since you've been so helpful, I'll double the value of this question to 1000 by setting up another for you later.
0
 
FrylockAuthor Commented:
Also, I don't see the 'select object tool' under the advanced menu.
0
 
Karl Heinz KremerCommented:
The tool is on the "Advanced Editing" _toolbar_, or you can find it as "Tools>Advanced Editing>Select Object Tool".

Check the following setting in Acrobat's Preferences: On the "JavaScript" dialog, is the "Enable Acrobat JavaScript" checkbox selected?
(It should be). Also select the "Enable JavaScript Debugger" setting and try again to see if you get any error messages in the console window.
0
 
FrylockAuthor Commented:
Hi,

Yes, the javascript is enabled and the "Enabled Acrobat Javascript" is working. There are no error messages.
0
 
FrylockAuthor Commented:
If you have WinXP I can give you remote desktop control. I can't find the "execute this goddam script" option or even see a list of them anywhere.
0
 
FrylockAuthor Commented:
Oh wait, I found it. It's called "fill database." I'm new to .js but not to coding. Anyway, it says 'error occured.'
0
 
FrylockAuthor Commented:
And here's the error:
Acrobat JavaScript Debugger Functions Version 6.0
Acrobat Database Connectivity Built-in Functions Version 6.0
Acrobat EScript Built-in Functions Version 6.0
Acrobat Annotations / Collaboration Built-in Functions Version 6.0
Acrobat Multimedia Version 6.0

TypeError: f1 has no properties
20:Folder-Level:App:db1.js
TypeError: f1 has no properties
20:Folder-Level:App:db1.js
0
 
FrylockAuthor Commented:
Oh damn, I fixed it. Problem Solved. I can take it from here, mack! Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 13
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now