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”:

14 Responses to Using URL Requests in PDF Forms

  1. Ernest says:

    Thanks for the info, it works great in populating box(es) on a form.One additional question. I am able to send, retrieve “RecordID”, and populate a textbox on the form with said “RecordID”. I have a data connection to SQL Server 2005, and would like to filter for a specific record OnOpen, with the sql query …”WHERE RecordID = ????. How do I get the the value retrieved from the URL, and placed in textbox “RecordID”, to populate the sql “Where” clause.ThanksErnest

  2. Ernest,I recently posted an article about doing just that: Selecting Specific Database Records.Please have a look at that sample. It should answer your questions.

  3. Dave P Nottingham says:

    StefanYour work on this was a real breakthough! The issue, and one that you address, is that of security! It seems that you can’t run a ‘POST’ against a pdf form – before moving to the .NET platform I used to use APToolkit in asp to move data into the respective fields, but that is very time consuming coding! Running the whole thing in a SLL window without address bar seemed an idea, but the URL is carried forward if no HTTP Title tag is formed as the title. Is there a way of including a title within the XML page to show at the top of the browser? I’ve had a look though:- not been able to find an answer!

  4. Dave,I understand what you’re getting at but unfortunately there’s nothing in the XDP spec that I know of which would let you specify the title.Ultimately, when you’re viewing a PDF in a browser, it’s the Acrobat plug-in (Mozilla) or ActiveX control (IE) that controls what you see in the title bar. My best guess at this point would’ve been to specify title metadata in the PDF itself (via “File | Properties”) but when the PDF contains an XFA Form, you can’t set that metadata.

  5. Pete Elmgreen says:

    Hello,I’m investigating options for a new project and came across sample URLRequests.pdfUnfortunately the file is damaged and cannot be openend w. Acrobat Prof 7.0.Please check the file and post a working fileThanksPete

  6. Pete,Thanks for bringing this to my attention.What happened is I saved the form as an Acrobat 7.0.5 Dynamic PDF form instead of an Acrobat 7.0 Dynamic PDF form which explains why you weren’t able to open it in something less than Acrobat 7.0.5.I’ve uploaded a new version of the file. Please let me know if you still have problems opening it.

  7. josh says:

    What is the specific javascript code you are using in the PDF to populate the feilds?I downloaded the sample PDF, but the security of the document is not letting me view the javascript code to get the URL Request code.I’m trying to populate a form by URL request and couldn’t find any other good info on the web except for this page.Thanks,Josh

  8. Greg says:

    Great info, but one question – I need this to run on the server. When we are populating the form with data, it All needs to happen on the server, as we don’t want anything but the web server to access to the database (the pdf form is actually being displayed inside of a .net web site).Is there any way to run a server script and pass some kind of value to it, like shown here?Thanks!-Greg

  9. Josh,The sample I posted is an XFA form saved as an Acrobat 7.0 Dynamic PDF file.You should be able to use Designer 7.0 or later to open it and see the script on the “Message” text field using the Script Editor palette.What kind of security problems are you experiencing when you’re attempting to find the script?

  10. Greg,Obviously, the URL Request information is being obtained from the host which is running on the client and therefore isn’t available to you on the server.Unfortunately, I don’t know enough about the way your web site works in order to think of a solution. Nothing “generic” is coming to me at the moment. How does a user request a particular form which is then served from the server application? What kind of information is it that you need to pass into the form?There must be some user interaction at some point during the process of selecting the form which will be served. This point of interaction may be a good opportunity to gather some information from the user and submit it to the server…

  11. Willie says:

    Is there some other property similar to to obtain the the url from a web browser when the user has entered a file id such as: file://c:\mypath\MyPdf.pdf? gives the file and path, but apparently not any parameters. Maybe the ?Param=Value syntax is only valid for http urls, if true, is there another syntax that I should be using to pass the parameter value in?My goal is to be able to pass parameters into an adobe pdf form, without using IIS.Thanks,Willie

  12. Willie,You should be able to get the parameters across if you use a URI to a file in your browser.For example, the following should work


    for a file located here:


    I understand you were saying that it’s not working for you but my file URI syntax is slightly different from yours…Also, beware that certain URI-encoded characters might give you some grief when using a URI to a local file. I don’t really know why but here’s an example: Including “%85” in my message for an exclamation mark produced an exception in one of the “decode” functions used in my sample form to convert the URI-encoded characters into regular characters.

  13. willie says:

    Still not working for me.Here is something that I did notice as being different…maybe it means something, maybe not:If I enter into my IE the URLfile://c:\mypath\myfile.pdfit gets translated intoc:\mypath\myfile.pdfand the returnsfile:///c|/mypath/myfile.pdfwhich is fine.If I start withfile:///c|/mypath/myfile.pdfI again get the same results as above.However, if my starting URL that I enter into IE 6 isfile://c:\mypath\myfile.pdf?param=valuethe translated URL in the IE bar becomesfile:///c:/mypath/myfile.pdf?param=valueNote that the file:// did not get stripped this time vs initially.The returnsfile:///c|/mypath/myfile.pdfwithout any parameters.And lastly, if I enter into IEfile:///c|/mypath/myfile.pdf?param=valuethe IE URL changes only slightly from the entered value tofile:///c:/mypath/myfile.pdf?param=valueand the return value from isfile:///c|/mypath/myfile.pdfagain without any parameters.Aside from not getting my parameters out, I thought it odd that the IE URL would strip the file:// notation whenever I did not try to include any parameters, but was kept when I did enter parameters.To be complete, if I place myfile.pdf inside the default IIS website path (c:\inetpub\wwwroot) and then enter into the IE URLhttp://localhost/myfile.pdfthe IE URL returns the identical value, as well as the I enter into IE URLhttp://localhost/myfile.pdf?param=valueboth the IE URL and return the identical value as input (including the ?param=value).Right now, this is an academic question for me to understand why I cant get it to work. As a matter of practical solution, I was able to embed the values of the parameters into the filename, and then parse them out.

  14. Willie,When I tested it myself, I was using FireFox think what’s happening is that depending on the browser and the syntax specified in the URI pointing to the file, the browser may treat the path either as a command to open a file (at which point the parameters after the “?” get passed to the application) or to browse to a file (which results in the parameters after the “?” being treated as an HTML Request).That’s the best answer I can come-up with. Thankfully, you were able to work around it.