These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

need help auto-filling a form from database

trayhumphrey
Registered: Jun 19 2008
Posts: 8
Answered

Hi,
I'm new to Acrobat JavaScript and Forms, but am a programmer in other environments. I am using Acrobat Professional 7.0 and Adobe Designer. The users will be using Acrobat Reader. I have a client-supplied PDF form with fields. I want to collect some information from the user and auto-fill the fields from a database.

I thought I would just add some combo boxes to the form to gather the lookup parameters and then be on my way. I added my first combo box at the top of the form using Adobe Designer, set up a data connection, and can see the first record in the combo box. But when I click on it in Acrobat Pro or Acrobat Reader, I get the "error sound", and no list dropping down.

I want the user to see these combo boxes only for data lookup. I do not want them printed in the final document. When I checked the document restrictions (Show Security Settings for this Document / Security tab), I see that changing the document is not allowed.

Is that my problem?

Can I change the restrictions?

Is there a better way to have the user provide selections to do a database lookup?

Can I essentially pass startup parameters to Acrobat Reader and do the lookup in document-level Javascript?

Sorry for my meandering questions, I just want to make sure I don't leave out a valid approach.

Thanks in advance for any ideas,
Ray

My Product Information:
Acrobat Pro 7.0.9, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are a few issues with accessing a database from a PDf. Fist, where is the user located relative to the DB? A livecycle form connects to a DB through OLEDB modules. I'm pretty sure that the modules that come with LC only connect to local databases, which means that your user would have to be local to your machine, or network. This doesn't mean that you can't find an OLEDB module for your DB that will work over the internet, I don't know. Everything is handled though a connection string. Acrobat simply hands off the connection string to the OLEDB module.

You can prepopulate list items from a DataConnection, i.e., anything in the LC DataView. Unfortunately this feature was added to LC Designer in version 7.1.

The next issue is that DB acess is something that can only be done in Acrobat Pro or Standard, and on Windows. It's not available in Reader or on the MAC.

But there is another way, and that's through the internet. Acrobat can perform HTTP Get and Post operations, and recieve data back from the server. This method will work on Acrobat and Reader for version 3 and later, and on the Mac and Windows platforms. Look in the JavaScript Reference at the "doc.submitForm()" function. This is the function that initiates HTTP request. All you have to do is write a server script that retrieves data form the DB, and returns it to Acrobat. To gain more control over the data transfer process I usually return data to invisble fields. Then use scripts on the LC form to parse and copy the data into the appropiate fields.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

trayhumphrey
Registered: Jun 19 2008
Posts: 8
Thanks for your response, Thom. Let me elaborate a little. I have CS2 with updates. From Help / About comes a splash that says "Adobe Acrobat Professional 7.0". Under that it says "Version 7.1.0". So perhaps I do have version 7.1. If I have Acrobat Pro 7.1 do I also have Adobe Designer 7.1? And what is the Livecycle Designer you mention? I do see the DataView windowyou mention in Adobe Designer.

My users are on Windows and have Acrobat Reader 7 or 8, but not Acrobat Pro. Are you saying that even if I customize a fillable form to populate from a database, that PDF is not accessible from Acrobat Reader? That could be a non-starter.

The database is SQL Server on the local network. There is actually a .NET web app, but at the outset I didn't see a way to integrate with a PDF. I figured I could customize the PDF to pull from the same database.

After my post yesterday, I found out about JSObject. Since this an internal web app with IE client, I thought I might be able to write browser script to create the AcroExch object, get the JSObject, and populate the fields in the PDF that way. Do you think that is more or less preferred than your HTTP solution?

I guess that is an issue of whether 1) the user launches Reader and chooses the database records from combo boxes to autofill the form (HTTP or ODBC), or 2) my application launches Reader and autofills the form. The latter is more integrated but as I'm the novice, I'm not sure which direction to take.

Hopefully I've given you enough information so that you can say, "Well since your users are using Acrobat Reader, you have to do blah, blah, woof woof."

Thanks again,
Ray
trayhumphrey
Registered: Jun 19 2008
Posts: 8
Okay, I did an RTFM on myself and cross-referenced an example in the Developer Guide with the JS Reference. I now see that the ADBC object, the one used to access a database, has a big fat X in the Availability column of the Quick Bar -- not available from Adobe Reader.

So I guess my options might be:
1) Use Doc.submitForm with bGet=true. What format should I return the data in from the web page? It sounds like from Thom's reply to my original post that the returned data automagically fills fields on the form. How does field/data matching occur?

Do I read correctly that if I use HTTP GET, I cannot use Reader within IE?

2) Is there a still a possibility of using JSObject to push the data to the PDF file when it is opened in Adobe Reader? I assume I can write browser script to create the AcroExch object and set the form fields when the PDF file is launched. Doing it server-side in .NET would be nice, but I don't know how I would do late-binding for JSObject.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In my first post I assumed that you had created your form in Adobe LiveCycle Designer (which is the full name of the product). Is this true?

Yes, you can use a VB app and IAC to both fill in a PDF form in Reader, or move data from the form into the DB. The VB app can be stand-alone, or VB script in some MS application. Of course the user has to have this VB app installed on thier local system. I don't know if a VB script in IE will work. The IE environment is considered somewhat suspect. There may be security restrictions that will get in the way, but it's worth a try to see what will work. I'd suggest making a standalone VB app first to get a feel for developing with IAC.

If all of your users are local and you have some measure of control over thier system setups, then I think the VB/IAC app is the way to go. This is a very direct and exact way to move the data.

But, if you're user's are remote, and you can't easily get them to install some VB app that thier IT dept may not be happy with. Then using HTTP request and a server script is the best way to go. This approach will work with Reader and IE reqardless of whether you use get or post to send data to the server. Data has to be returned from the server script in the body of the HTTP response in a format that Acrobat and the PDF will understand. There are several data formats, but they work the same way. Values are matched to fields with the field names. All of the formats are variations on Name/value pairs. All of the formats you can use with your document are listed in the data Export/Import file dialogs. Open up your form in Acrobat, and from the "Form" menu select "Manage Form Data > Export data". Just do a web search on the formats to find out the details.Regarless of which method you use. If you want the user to be able to save the filled in PDF file locally, it will need to be Reader Enabled. Which cannot be done from Acrobat 7 Pro. But this feature is in Acrobat 8 Pro.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

trayhumphrey
Registered: Jun 19 2008
Posts: 8
Thanks for your advice, Thom. Just to wrap-up, "LC" was a big Duh! on my part because I didn't know the full name of the product, Adobe Livecycle Designer. The title bar just says Adobe Designer in version 7 so I was clueless.

I tried creating the AcroExch object from my browser, client-side, but it failed. In my continued research over the weekend, I also found the iTextSharp library, a C#.NET port of the OpenSource iText for Java. It permits detailed, object-oriented creation and manipulation of PDF files.

I have a simple example working that opens the PDF file on the server, fills in the form fields, and streams the data that is viewed in the browser at the client. The user is allowed to review and change the form, then save a copy.

I just ordered an upgrade to CS 3.3 which will have Acrobat and LC Designer 9 in it. It should be available next week. It was time to upgrade.

I'll continue climbing my learning curve with Adobe. Thanks for the help along the way.

Ray