使用iTextSharp填写pdf时BadPasswordException [英] BadPasswordException when filling out pdf with iTextSharp

查看:152
本文介绍了使用iTextSharp填写pdf时BadPasswordException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有第三方PDF文件,其中包含一些表单字段,我需要以编程方式填写。 PDF文件是安全的。详细的安全设置: SecurityMethod:密码安全,文档打开密码:否,...表单字段填写或签名:允许...
当我'我试图手动打开并填写文档,一切正常,我没有被要求输入任何密码。但是使用代码时,它会失败并出现异常。
这是代码(我正在使用iTextSharp库):

I have a third-party PDF file with some form fields, that I need to fill out programmatically. PDF file is secured. Detailed security settings: SecurityMethod: Password Security, Document Open Password: No, ... Form Field Fill-in or Signing: Allowed... When I'm trying to open and fill out the document manually, everything is ok, and I'm not asked for any password. But with the code, it fails with exception. Here's the code (I'm using iTextSharp library):

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

创建PdfStamper对象失败,异常: BadPasswordException。 PdfReader没有用所有者密码打开。

Creating the PdfStamper object fails with exception: BadPasswordException. PdfReader not opened with owner password.

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

Any ideas, why it fails with code, but not manually? Thanks in advance.

推荐答案

您是否尝试过添加

PdfReader.unethicalreading = true; 

在你的读者初始化之前?

这篇关于使用iTextSharp填写pdf时BadPasswordException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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