Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 646
Skog Avatar asked Aug 15 '12 16:08

Skog


1 Answers

Have you tried adding

PdfReader.unethicalreading = true; 

before your reader initialization?

like image 61
Michal Klouda Avatar answered Oct 04 '22 05:10

Michal Klouda