我如何用iTextSharp预填充PDF表单,同时仍然让其他用户在Adobe Reader中对其进行编辑和保存? [英] How can I prefill a PDF form with iTextSharp while still having it be editable and saveable in Adobe Reader by other users?

查看:132
本文介绍了我如何用iTextSharp预填充PDF表单,同时仍然让其他用户在Adobe Reader中对其进行编辑和保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我有一个表单模板,该模板具有一些使用iTextSharp库从数据库中预填充的字段。然后,用户将填写其余字段并保存填写的表格。然后,我将提取数据并将其放入数据库中。

Right now I have a form template that has some fields that are prefilled from a database using the iTextSharp library. Users will then fill in the rest of the fields and save the filled out forms. I'll then extract the data and put it in the database.

当前,我能够创建PDF,并且可以很好地进行预填充。我什至可以编辑它们并将其保存在计算机上的Adobe Reader中。但是,我发现其他人打开这些​​文件时,不允许他们保存表单。

Currently I am able to create the PDFs and they are pre-filling just fine. I'm even able to edit and save them in Adobe Reader on my computer. However I'm finding when anyone else opens those same files, they're not allowed to save the forms.

我该怎么做才能让所有使用Adobe Reader的用户保存表格?这是我创建PDF的代码:

What do I need to do to allow the forms to be saved by all users using Adobe Reader? Here's the code I have to create the PDF:

Dim pdfReader As PdfReader = New PdfReader(formPath)
pdfReader.RemoveUsageRights()
Dim pdfStamper As PdfStamper = New PdfStamper(pdfReader, New FileStream(outputPath, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
Dim xfdfReader As XfdfReader = New XfdfReader(xfdfPath)

pdfFormFields.SetFields(xfdfReader)
pdfStamper.Close()

我曾经遇到过一个问题,就是即使我也无法在Reader中保存表格,这就是为什么我添加以下行:

I used to have the problem that even I couldn't save the forms in Reader, and that's why I added this line:

pdfReader.RemoveUsageRights()

这使得 I 可以编辑它创建的PDF,这使我认为一切都已解决。但是没有其他人可以。

That made it so that I can edit the PDF it creates, which made me think everything was resolved. But nobody else can.

推荐答案

请参考示例 ReaderEnabledForm.cs 。它描述了填写Reader Enabled表单的不同方法:

Please consult the example ReaderEnabledForm.cs. It describes different ways to fill out a Reader Enabled form:


  1. 破坏启用阅读器的功能

  2. 删除启用阅读器的功能

  3. 保留阅读器的功能

您已经尝试过1和2,而您要输入3,则需要在创建PdfStamper实例时添加额外的参数:

You've already tried 1 and 2, whereas you're asking for 3, involving adding extra parameters when creating a PdfStamper instance:

new PdfStamper(pdfReader, New FileStream(outputPath, FileMode.Create), '\0', true);

这篇关于我如何用iTextSharp预填充PDF表单,同时仍然让其他用户在Adobe Reader中对其进行编辑和保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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