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

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip