For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Sunday, January 04, 2015

itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password

Problem:

If you are using iTestShap in Dot net application and generating PDF with owner passward. After that you are trying to open that password protected in again in Dot net code then you may face the error or exception of itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password.

Solution:

This is because you are not supplying the password while you opening that pdf file in itextsharp using PdfReader.

Example:

Creating Pdf file using owner password:

PdfWriter docWriter = PdfWriter.GetInstance(doc, new FileStream(pdfFileName, FileMode.Create));
byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
docWriter.SetEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);

Now you are trying to open that file:

PdfReader pdfReader = new PdfReader(pdfFileName);

Correct code:

byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
PdfReader pdfReader = new PdfReader(pdfFileName, OWNER);

So conclusion is that be sure you are supplying the password while opening the password protected file in PdfReader in C# or VB.net code:
Share:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive