我需要填写一个PDF Web表单,该表单将向公众提供从URL查询字符串中获取的数据。我不希望用户能够在表单上编辑任何内容 - 只打印或保存。
我意识到这不是最安全的方式,因为他们可以编辑查询字符串来修改数据。有更安全的方式吗?
我目前正在尝试使用最简单的方法:pdf表单和表单中的javascript。
代码如下,但尚未经过正确测试。我想知道这是否是正确的做法?
// 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])
}
}
}
}