禁用与iTextSharp的扩展功能 [英] Disable extended features with iTextSharp

查看:294
本文介绍了禁用与iTextSharp的扩展功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有启用扩展功能的形式PDF模板。使用这种形式的字段填写后的 iTextSharp的的,用Acrobat Reader软件的用户得到的错误消息:




该文件在Adobe Reader中启用的扩展功能。该文件有,因为它创建和使用扩展功能不再是
提供
被更改。请联系笔者对于这种
文档的原始版本。




我GOOGLE了一下,但所有的帖子谈启用扩展功能,但是,我想表单字段保持的停用并扩展功能的关闭



下面这我使用的示例代码:

 使用(VAR existingFileStream =新的FileStream(fileNameExisting,FileMode.Open))
按(VAR newFileStream =新的FileStream(fileNameNew,FileMode.Create))
{
//打开现有PDF
变种pdfReader =新pdfReader(existingFileStream);

// PdfStamper,这将创造
变种模子=新PdfStamper(pdfReader,newFileStream);

变种形式= stamper.AcroFields;

VAR fieldKeys = form.Fields.Keys;

的foreach(在fieldKeys串fieldKey)
{
如果(fieldKey.Equals(零售商名称))
form.SetField(fieldKey,retailerName);
}
//拼合的形式,以便它不会是编辑/可用了
stamper.FormFlattening = TRUE;

stamper.Close();
pdfReader.Close();
}


解决方案

iText关键字读者启用PDF文件指向以下信息:




布鲁诺Lowagie于星期五,12/31/2010 - 16:37




填写我的表格后,我的PDF显示以下信息:此文档启​​用在Adobe Reader扩展功能。因为它是建立和使用扩展功能不再可用该文件已被更改。请联系笔者对于本文档的原始版本。如何避免此消息?




形式的创建者作出使阅读器的文档。读者使只能使用Adobe软件来完成。您可以通过两种方式避免此消息:




  • 取出使用权。这将导致一种形式,将不再启用读卡器。例如:如果文档的创建者允许的填写表格可以被保存在本地,这将不再删除使用权后,可以

  • 填写追加模式的形式。 。这将导致一个更大的文件的大小,但阅读器能够将被保留。




它还分在样品 ReaderEnabledForm.java (在C#/ iTextSharp的当量,其中是的ReaderEnabledForm.cs )展示了如何做到无论是。



你的情况,这相当于调用

  pdfReader.RemoveUsageRights(); 

在创建之后的 PdfReader 和创建前在 PdfStamper。

  / ** 
*移除所有这此PDF可以具有使用权限。仅以Adobe可以授予使用权
*和与iText的PDF格式的任何修改都将它们无效。无效的使用权可以
*混淆Acrobat和它的advisabe干脆删除它们。
* /
公共无效RemoveUsageRights()


I have a PDF template with a form with the Extended features enabled. After filling in the fields of this form using iTextSharp, a user with acrobat reader gets the error message:

This document enabled extended features in Adobe Reader. The document has been changed since it was created and use of extended features is no longer available. Please contact the author for the original version of this document.

I googled a bit but all the posts talk about "enabling" extended features, however, I want the form fields to remain disabled and extended features turned off

Here a sample code which I am using:

using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
using (var newFileStream = new FileStream(fileNameNew, FileMode.Create))
{
    // Open existing PDF
    var pdfReader = new PdfReader(existingFileStream);

    // PdfStamper, which will create
    var stamper = new PdfStamper(pdfReader, newFileStream);

    var form = stamper.AcroFields;

    var fieldKeys = form.Fields.Keys;

    foreach (string fieldKey in fieldKeys)
    {
        if (fieldKey.Equals("Retailer Name"))
            form.SetField(fieldKey, retailerName);
    }
    // "Flatten" the form so it wont be editable/usable anymore
    stamper.FormFlattening = true;

    stamper.Close();
    pdfReader.Close();
}

解决方案

The iText Keyword: Reader enabled PDFs points to the following information:

Submitted by Bruno Lowagie on Fri, 12/31/2010 - 16:37

After filling out my form, my PDF shows the following message: This document enabled extended features in Adobe Reader. The document has been changed since it was created and use of extended features is no longer available. Please contact the author for the original version of this document. How do I avoid this message?

The creator of the form made the document Reader enabled. Reader enabling can only be done using Adobe software. You can avoid this message in two ways:

  • Remove the usage rights. This will result in a form that is no longer Reader enabled. For instance: if the creator of the document allowed that the filled out form could be saved locally, this will no longer be possible after removing the usage rights.
  • Fill out the form in append mode. This will result in a bigger file size, but Reader enabling will be preserved.

It also points to the sample ReaderEnabledForm.java (the C#/iTextSharp equivalent of which is ReaderEnabledForm.cs) which shows how to do either.

In your case this amounts to calling

pdfReader.RemoveUsageRights();

right after creating the PdfReader and before creating the PdfStamper.

/**
 * Removes any usage rights that this PDF may have. Only Adobe can grant usage rights
 * and any PDF modification with iText will invalidate them. Invalidated usage rights may
 * confuse Acrobat and it's advisabe to remove them altogether.
 */
public void RemoveUsageRights()

这篇关于禁用与iTextSharp的扩展功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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