编辑浏览器中嵌入的pdf并将pdf直接保存到服务器 [英] Edit pdf embedded in the browser and save the pdf directly to server

查看:265
本文介绍了编辑浏览器中嵌入的pdf并将pdf直接保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个工作流程。


  1. 将包含表单字段的pdf加载到浏览器中(pdf在iframe或div中)。

  2. 用户填写

  3. 用户点击提交按钮(在另一个div中)以保存pdf。

我想在#3中做的是收集与表单字段相关的所有数据,并将数据保存到数据库表中。我不希望用户将pdf保存到他/她的本地计算机并将其上传到服务器。我想让它更加用户友好。



我将在服务器端使用Java / JSP / Servlet。我查看了似乎在处理pdf文件时流行/众所周知的itext,但是itext似乎用于生成/编辑pdf,但我不确定是否有任何方法可以使某个功能能够编辑嵌入浏览器的pdf并保存到数据库。



是否有任何adobe软件提供某种功能,我可以注入某种可以捕获用户的脚本提交?我知道PDF不是前端脚本语言,但我只想问。



我打算创建一个HTML表单,看起来像这个PDF并填充它当用户点击提交按钮进入PDF时,但正如我所说,我想让它更加用户友好。



我很感激,如果有的话任何看过这种类型的功能或已经完成它的人都会给我一些资源或提示。

解决方案

我的假设:你有一个具有类似于示例显示了如何添加按钮到现有的表格。请注意,有比此示例中描述的选项更多的选项。



例如:




  • 您也可以通过调整一些参数来使用GET,而不是使用POST方法。

  • 您还可以将完整的PDF(数据+表单)提交给服务器,但这只有在最终用户使用Adobe Acrobat作为插件时才有效。如果插件仅仅是Adobe Reader,则无效。

  • ...



为了向您展示提交表单时的期望,我写了 ShowData servlet。此servlet返回发送到服务器的字节。



如果是POST:

  personal.loginname = jdoe& personal.name = John + Doe& personal.password = test& personal.reason = reason& post.x = 29& post.y = 7 

请注意,我还定义了按钮,使我的点击坐标传递给服务器。你可能不需要这个。



如果是FDF:

 %FDF-1.2 
%ãÏ
1 0 obj
<< / FDF<< / Fields [< / lt; / T(FDF)>>< < / Kids [<< / T(登录名)/ V(jdoe)>><< / T(姓名)/ V(John Doe)>><< / T(密码)/ V(试验)>><< / T(原因)/ V(原因)GT;>] / T(个人)GT;>] / ID并[d EF0089E16ED50F11CB6057A700B9046E>< 1205D069D1D6AE37665B6FF7EEA65414> ]>> /类型/目录>>
endobj
预告片
<< / Root 1 0 R>>
%% EOF

如果是XFDF:

 <?xml version =1.0encoding =UTF-8?> 
< xfdf xmlns =http://ns.adobe.com/xfdf/xml:space =preserve
>< f href =http://itextpdf.com: 8180 / book / submit_me.pdf
/>< fields
>< field name =XFDF
/>< field name =personal
>< field name =loginname
>< value
> jdoe< / value
>< / field
><字段名称=name
>< value
> John Doe< / value
>< / field
>< field name =password
>< value
> test< / value
>< / field
>< field name =reason
>< value
>原因< / value
>< / field
>< / field
>< / fields
>< ids original =EF0089E16ED50F11CB6057A700B9046Emodified =1205D069D1D6AE37665B6FF7EEA65414
/>< / xfdf
>

在理想的世界中,这将是您的解决方案。它在ISO-32000-1中描述,它是PDF的世界标准。但是:许多人开始使用不支持此功能的糟糕PDF查看器,因此如果您想使用此解决方案,则必须确保人们使用体面的PDF查看器作为其浏览器插件。


I have this workflow.

  1. Load a pdf containing form fields into the browser (pdf in iframe or div).
  2. A user fills it out
  3. A user click 'Submit' button (in another div) to save the pdf.

What I would like to do in #3 is to collect all the data associated with the form fields and save the data to the database table. I don't want a user to save the pdf to his/her local computer and upload it to the server. I would like to make it more user-friendly.

I am going to use Java/JSP/Servlet in the server-side. I looked into the itext which seems to be popular/well-known for handling a pdf file, but itext seems to be used for generating/editing a pdf, but I am not sure if there is any way to have a feature being able to edit a pdf embedded in the browser and save to the database.

Is there any adobe software providing some kind feature which I can inject some kind of script which can capture a user's submit? I know that PDF is not a front-end scripting language, but i am just asking.

I was going to create a HTML form which looks like this PDF and populate it into the PDF when a user clicks 'submit' button, but as I said, I would like to make it more user-friendly.

I'd appreciated if there is anybody who has seen this type of feature or has done it gives me some resources or tip.

解决方案

My assumption: you have an interactive PDF document with AcroForm fields similar to submit_me.pdf:

The main difference, is that I have different buttons on the form:

  • POST will post the data I fill out as if the PDF was an HTML form,
  • FDF will post the data to the server in the Forms Data Format, a format that is very similar to PDF, but that only contains the data pairs, not the actual form,
  • XFDF will post the data to the server in the XML Forms Data Format, which is the XML version of the Forms Data Format.
  • RESET will reset all the fields to their initial value.

The SubmitForm example shows how the buttons were added to an existing form. Note that there are more options than the ones described in this example.

For instance:

  • Instead of using the POST method, you can also use GET by tweaking some of the parameters,
  • You can also submit the complete PDF (data + form) to the server, but this will only work if the end user has Adobe Acrobat as plug-in. This won't work if the plug-in is merely Adobe Reader,
  • ...

To show you what to expect when you commit a form, I wrote the ShowData servlet. This servlet returns the bytes that are sent to the server.

In case of a POST:

personal.loginname=jdoe&personal.name=John+Doe&personal.password=test&personal.reason=reason&post.x=29&post.y=7

Note that I also defined the button in such a way that the coordinate of my click is passed to the server. You probably don't need this.

In case of FDF:

%FDF-1.2
%âãÏÓ
1 0 obj
<</FDF<</Fields[<</T(FDF)>><</Kids[<</T(loginname)/V(jdoe)>><</T(name)/V(John Doe)>><</T(password)/V(test)>><</T(reason)/V(Reason)>>]/T(personal)>>]/ID[<EF0089E16ED50F11CB6057A700B9046E><1205D069D1D6AE37665B6FF7EEA65414>]>>/Type/Catalog>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

In case of XFDF:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"
><f href="http://itextpdf.com:8180/book/submit_me.pdf"
/><fields
><field name="XFDF"
/><field name="personal"
><field name="loginname"
><value
>jdoe</value
></field
><field name="name"
><value
>John Doe</value
></field
><field name="password"
><value
>test</value
></field
><field name="reason"
><value
>Reason</value
></field
></field
></fields
><ids original="EF0089E16ED50F11CB6057A700B9046E" modified="1205D069D1D6AE37665B6FF7EEA65414"
/></xfdf
>

In an ideal world, this would be your solution. It is described in ISO-32000-1 which is the world-wide standard for PDF. However: many people started using crappy PDF viewers that do not support this functionality, so if you want to use this solution, you'll have to make sure that people use a decent PDF viewer as their browser plug-in.

这篇关于编辑浏览器中嵌入的pdf并将pdf直接保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆