How can I prefill a PDF PDF form using the url query string (or better method)?

I need to fill out a PDF web form that will be publicly available with data taken from the URL query string. I don't want the user to be able to edit anything on the form - just print or save it.

I understand this is not the safest way as they can edit the query string to change the data. Is there a safer way?

I am currently trying to do this using the simplest way: pdf form and javascript on form.

The code follows, but has not been tested properly. I am wondering if this is the correct approach?

 // This code was taken from:
 // http://blogs.adobe.com/pdfdevjunkie/2009/12/populating_pdf_form_fields_fro.html
 // Accessed: June 15, 2015

 //only run the script if the PDF file is being viewed in a browser window
 if (this.external)
 {
     //The whiteList defines which fields are permitted to be changed by the URL.
     //If you want all fields to be changed, leave the array empty as in "[]"
     //whiteList = ["Name", "Address", "City", "State", "ZipCode"]
     whiteList = []

     //get the parameters portion of the URL and unescape it so we get the spaces and punctuation back
     parametersString = this.URL.substring(this.URL.indexOf("?")+1)
     //only run the script if there are parameters
     if (parametersString.length > 0)
     {
         //create an array of key/value pairs
         parameters = parametersString.split("&")
         //loop through the array...
         for each (parameter in parameters)
         {
             //create a 2 element array for each parameter as [key, value]
             kvPair = parameter.split("=")
             //set the field named "key" to "value"
             fieldName = unescape(kvPair[0])
             if (whiteList.length > 0)
             {
               if (whiteList.indexOf(fieldName) > -1)
               {
                   this.getField(fieldName).value = unescape(kvPair[1])
               }
             }
             else
             {
                this.getField(fieldName).value = unescape(kvPair[1])
             }
       }
   }
}

      

+3
javascript pdf


source to share


No one has answered this question yet

Check out similar questions:

2701
How do I get the values ​​of a query string in JavaScript?
238
Is there a way to get the url without the query string?
183
How to pass parameters in GET requests using jQuery
1
Angular 4: Can't update url query string
1
How can I access browser local storage using PDF-JavaScript?
0
.pdf form submit as HTML - how to handle response in JavaScript?
0
JavaScript: adding query string to url based on input field values ​​if set?
0
Get dynamic query string parameters from url - AngularJS
0
How do I pass an array to CFPDFFORM and fill the PDF inputs with the key / values ​​in my array?
0
Synchronize HTML form with url query string?



All Articles
Loading...
X
Show
Funny
Dev
Pics