BadPasswordException when filling out pdf with iTextSharp

末鹿安然 提交于 2019-12-06 00:04:29

问题


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);

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.


回答1:


Have you tried adding

PdfReader.unethicalreading = true; 

before your reader initialization?



来源:https://stackoverflow.com/questions/11973400/badpasswordexception-when-filling-out-pdf-with-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!