首页 文章

使用iTextSharp填写pdf时BadPasswordException

提问于
浏览
7

我有一个带有一些表单字段的第三方PDF文件,我需要以编程方式填写 . PDF文件是安全的 . 详细的安全设置: SecurityMethod: Password Security, Document Open Password: No, ... Form Field Fill-in or Signing: Allowed... 当我'm trying to open and fill out the document manually, everything is ok, and I' m没有要求输入任何密码时 . 但是使用代码时,它会失败并出现异常 . 这里's the code (I' m使用iTextSharp库):

var str = new MemoryStream();
var reader = new PdfReader(_path);
var stamper = new PdfStamper(reader, str);

创建PdfStamper对象失败,但异常: BadPasswordException. PdfReader not opened with owner password.

任何想法,为什么它失败的代码,但不是手动?提前致谢 .

1 回答

  • 19

    你试过添加吗?

    PdfReader.unethicalreading = true;
    

    reader 初始化之前?

相关问题