Using URL Requests in PDF Forms

Here’s a sample in response to “Ernest’s question”: on passing values to PDF forms via URL. His intent is to use it to provide a key to a PDF form such that it can be used to filter records from an “ODBC Data Connection”: in order to pre-populate the form with data.

I love these kinds of questions because they challenge me to find answers!

Of course, this is quite specific but there are many other uses for this. In fact, you could have a whole lot of fun with it too! You could even use this to alter the appearance of your form: Say you had one form that you were using for multiple departments in your company and every department had its own header. You could place each header in a subform, make them all hidden and then, based on the URL request which would include a department code, decide which one to show — no XML Data file, database connection or web service needed!

Beware, however, that URL request strings are *not secure* because they get posted in plain text for anyone to read so be careful of the information you pass-in to your form this way.

This sample form looks for a “message” and a “color” key in the URL request in order to show a message in a text field and change the text field content area’s color (an RGB value). For example:

* == //URLRequests.pdf?message=Isn’t%20this%20cool%3F == — Shows the message “Isn’t this cool?” in the text field.
* “//URLRequests.pdf?message=Think%20of%20the%20possibilities…&color=0%2C255%2C0”:…&color=0%2C255%2C0 — Shows the message “Think of the possibilities…” in the text field and makes the text field green.

“Download Sample [pdf]”:

*Minimum Requirements:* Designer 7.0, Acrobat 7.0.

The trick to all this is obtaining the URL that was used to access the PDF form. This can easily be achieved by accessing the “Acrobat Document Object”: associated with the form and then obtaining the value of its _URL_ property. This is done in JavaScript via the “Message” text field’s Initialize event:bc. property will give you the following string (from the second sample URL I provided earlier):bc. //URLRequests.pdf?message=Think%20of%20the%20possibilities…&color=0%2C255%2C0From there, it’s just simple JavaScript code to extract the requestbc. ?message=Think%20of%20the%20possibilities…&color=0%2C255%2C0and then parse the key/value pairsbc. message=Think%20of%20the%20possibilities…color=0%2C255%2C0Finally, since we’re passing-in a string that may contain spaces which will have been URI-encoded (that’s use of “%20” instead of spaces and “%2C” instead of commas in the request string), we need to decode it back to a normal string using JavaScript’s built-in “decodeURI” and “decodeURIComponent” functions:bc. decodeURI(decodeURIComponent(string))If you want to have fun submitting different strings to show in the message box, I found a little tool online which “converts regular strings into URI-encoded strings”: