|
Home |
Form Data Handling
| |
Loading data from an outside source means parsing data. Data is typically acquired from a file in the file's native format. Parsing is the process of dividing the raw data up into useful bits. Text based formats are simplest to parse and there are several very common formats that are exported from all the major data applications. Here is a short list.
- CSV - Comma separated value, has a ".csv" extension. The first line in the file is a list of column names, separated by commas. Each following line is a comma separated list of values. One for each of the columns defined in the first line. Standard JavaScript string operators are used to parse data.
- TSV - Tab separated value, has a ".txt" extension. Exactly like the CSV format except values are separated by tab characters.<.li>
- XML - There are two XML parsers built into the Acrobat JavaScript model. One is the E4X model, which is part of core JavaScript. The other is the XMLData model that was added to support LiveCycle forms. The raw XML file data can be passed directly into either one of these models.
- JSON
-
More info on parsing these formats can be found in the article on Acquiring Raw File Data.
There are two main environments in which forms are used, open and closed. In an open environment the forms are widely distributed to unknown users. The developer has no control over the type and version of Acrobat, or any other system parameters. In this case everything that is needed to acquire and/or update the auto-populate data must be contained within the PDF, and the scripts must operate in the most restrictive setting. In a closed environment the developer has some control over the user's system. This is the case for a form that is only used in the office, by a clerk behind a counter, or is distributed to known vendors. In this case the external data can be store in a greater variety of ways.
Here's a list of different ways to store/acquire external data.
- PDF File Attachment - A file attachment travels with the PDF. It can be read by Acrobat or Reader versions 7 or later. But it can only be realistically updated in Acrobat Professional. This is a good option for widely distributed forms where the data is only updated by the forms originator.
- Local File System - Common data file types such as XML and CSV can be loaded directly in Acrobat Professional 7 and later, and in Adobe Reader X and later, but requires a folder level script. This option is perfect for office and other closed environments.
- Remote Data File - There are three ways to get data
- Global Object
- Database
One easy to use technique is to store the data in a file attachment to the form. The data travels with the form, so it is easy for the scripts to access, and it is easily updated by simply overwriting the old attachment with a new one, and then sending out new forms.
The two most easily handled data formats for storing the data are CSV (comma separated values) and XML. CSV is a very simple text format and Acrobat JavaScript has two different XML parsers built into the model. More information on parsing these formats can be found in the article on Acquiring Raw File Data.
There are 2 steps to using data stored in a file attachment.
1. Read the raw data from the attachment
2. Parse the data into a local JavaScript object.
Acquiring the Auto-Populate Data from an External File
Storing the Auto-Populate Data in the Global Object
|