Using the ADBC JavaScript Object

ADBC or Acrobat Database Connectivity is a javascript object (derived from the Plugin) that allows you to connect to almost any type of database and display data directly in your PDF documents.

To demonstrate a quick example you’ll need to download the example files acrotips.mdb, acrotips6006.pdf and AcroTips6006JS.txt. The example PDF has three buttons, one button connects to the database, and two other buttons to navigate the records in the sample database.

In the example database there is only one table ‘Customers’, there are five columns ‘CustomerID’, ‘FirstName’, ‘LastName’, ‘SSN’, ‘Comments’ and ‘Address’. These match the form fields with the same names.

I have also created three form buttons ‘Connect’, ‘First Record’ and ‘Next Record’.

To make life a little simpler the code required to make this example work is contained within one Document Level Javascript – ‘AcroTips6006’. Inside the javascript are several ‘functions’ or blocks of processing code.

For example there is a function to connect to the database called ‘Connect’ activated by the Connect button, there is also one for the First Record button called ‘firstRecord’ and also one for the Next Record button ‘nextRecord’.

Making a connection to a database is easy, you firstly need to create a Data Source Name [DSN] (Control Panel>ODBC/DataSources) – create a new DSN based on the Microsoft Access Database Driver, and select the ‘acrotips.mdb’ database.

The name you assign to the DSN is the name you use to connect to the database inside Javascript/Acrobat. It’s that easy!

For example in the Connect function you will see a line of code as follows:

dbConn = ADBC.newConnection('AcroTips');

‘AcroTips’ was the name of the DSN I created (note the case). Once we have the ‘connection’ to the database we can execute Structure Query Language (SQL) statements against it.

If you now click the ‘Connect’ button the PDF will have a connection to the sample database and will let you look through the records in the database by using the other two form buttons.

To summarise this tip, the basic steps required are:

  • Create form fields to match those in your database.
  • Make a Data Source Name (DNS) using control panel and select your database.
  • Create a javascript function to connect to the database using the DSN assigned name as the connection name.
  • Create an execute an SQL Statement
  • Cycle over the query results by using buttons to activate other javascript functions. (ie, First Record and Next Record).

You May Also Like

About the Author: Dave Wraight

Leave a Reply