Tips & Tricks

Using the ADBC JavaScript Object

September 05, 2003

Advertisement
Advertisement
 

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).

Copyright Dave Wraight & Planet PDF. No unauthorised reproduction, distribution or publication permitted.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.