将数字动态附加到 PDF 或使提交按钮根据该数字更改其 URL
我正在从 SQL 数据库提供 PDF 并在浏览器中呈现它们。我正在尝试找出一种在 PDF 中动态嵌入数字的方法,以便在用户提交 XML 表单数据时可以使用该 PDF SQL 记录的 recordID。用户点击表单上的提交按钮,表单将其 XML 数据提交到我的提交页面。如果有某种方法可以动态更改提交 URL,那么我可以执行一个查询字符串来向我自己传递 recordID。我不是用代码生成 PDF,它是手动创建的,然后上传到我的网站。
编辑
向用户提供一个链接someServer.com/pdfLink.aspx?formID=5
,他们进入该链接,页面从数据库中提取 PDF 并显示它。这会在浏览器中显示全尺寸的 acrobat,因此我的 aspx 页面无法控制提交完整的表单,而 Acrobat 可以。用户填写表单并点击表单中的提交按钮。此提交按钮是在表单设计时设置的,指向另一个页面 someSite.com/pdfSubmit.aspx
提交按钮将 XML 数据发布到该页面,我可以处理它。我需要 someSite.com/pdfSubmit.aspx
页面的查询字符串中的 recordID。为此,我需要修改 PDF 以将 recordID 和查询字符串添加到提交按钮的提交 URL,或将其嵌入到 PDF else ware 中。最大的问题是如何在通过 someServer.com/pdfLink.aspx?formID=5
显示 PDF 之前修改 PDF 以执行这两个选项中的任何一个。
I'm serving up PDFs from a SQL db and presenting them in the browser. I'm trying to figure out a way to embed a number in the PDF dynamically so that the recordID for that PDFs SQL record is available to me when the user submits the XML form data. The user hits the submit button on the form and the form submits its XML data to my submission page. If there is some way of changing the submission URL on the fly then I could do a query string to pass my self the recordID. I'm not generating the PDF in code, its being created by hand and then uploaded to my site.
Edit
User is given a link someServer.com/pdfLink.aspx?formID=5
they go there and that pages pulls a PDF from the DB and displays it. This pulls up acrobat in browser full size so my aspx page isn't in control of submitting the completed form, Acrobat is. The user fills out the form and hits the submit button in the form. This submit button was set up at form design time to point to another page someSite.com/pdfSubmit.aspx
The submit button posts the XML data to that page and I can process it. I need the recordID in the query string for the someSite.com/pdfSubmit.aspx
page. To do this I would need to modify the PDF to either add the recordID and query string to the submit button's submit URL, or embed it in the PDF else ware. The big question is how do I modify the PDF just before I display it via someServer.com/pdfLink.aspx?formID=5
to do either of these two options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 PDF 中嵌入数字并不完全符合规范,但您可以采取一些措施来遵守规范。
当前的 PDF 规范规定“文件的最后一行应仅包含文件结束标记,
但有一些回旋余地 - 实现细节表明它在技术上不必是文件的最后一行,但只需要出现在最后 1K 中,一般来说,如果你不搞太多事情,大多数合规的读者甚至不会眨眼,如果我必须这样做,我会倾向于添加一个换行符(如果没有),然后是一个 % (这是一个 PDF 注释),一个让我知道它是我的标记,最后是数字,所以类似:
kMyMarkerString 应该类似于“MyApplicationDocumentIdentifier:”或类似的东西 。这将使您轻松识别您的足迹。
Embedding a number in PDF is not exactly kosher, but there are some things that you can do that will honor the spec.
The current PDF spec says that "The last line of the file shall contain only the end-of-file marker
but there is some wiggle room - the implementation details say that it doesn't technically have to be the last line of the file, but only has to appear in the last 1K and, generally speaking, if you don't muck with things too much, most compliant readers won't even blink. If I had to do this, I would be inclined to add a newline (if there isn't one), then a % (which is a PDF comment), a marker to let me know it's mine, and finally the number. So something like:
kMyMarkerString should be something like "MyApplicationDocumentIdentifier:" or some such thing that will make it easy to identify your tracks.
查询字符串是只读的,因此您无法在运行时动态更改它。但是,您可以:
在最初呈现提交页面时将 recordID 添加到表单
您可以处理提交表单吗然后使用添加到查询字符串的 recordid 参数执行 Response.Redirect 或 Server.Transfer 到正确的页面
The querystring is read-only so you cannot dynamically change it at runtime. However can you:
Add the recordID to the form at the time the submit page is initially rendered
Can you process the submit form and then do a Response.Redirect or Server.Transfer to the correct page with the recordid parameter added to the querystring
在尝试 @plinth 的建议时,我意识到我必须更改 XML 提交(因为他的数据直接在 PDF 上)。所以我更改了表单以 XDP 形式提交,其中包含 XML 数据 + 嵌入 PDF。当我这样做并查看原始 XDP 时我提交的表单遇到了这一点,
请注意,它自动包含具有我需要的 formID 值的 PDF 的 url,因此我所要做的就是从表单中获取 XDP 而不是纯 XML 帖子。它给了我我需要的一切。
While trying @plinth's suggestion I realized I had to change from XML submission (since his data was on the PDF directly. So I changed the form to submit as XDP which has XML data + embedded PDF. When I did this and viewed the raw XDP that the form submitted I ran across this.
Notice the 2nd to last line. It automatically includes the PDF's url which had the formID value that I needed. So all I had to do was get the XDP instead of pure XML post from the form and it gives me everything I needed.