Skog
Skog

Reputation: 513

BadPasswordException when filling out pdf with 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);

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.

Upvotes: 7

Views: 6911

Answers (1)

Michal Klouda
Michal Klouda

Reputation: 14521

Have you tried adding

PdfReader.unethicalreading = true; 

before your reader initialization?

Upvotes: 22

Related Questions