» Archive for the 'iTextSharp(iText#)' Category

Watermarking PDF documents using HttpHandlers

Monday, May 12th, 2008 by rubypdf

Published: 03 Oct 2007
By: Deepak Raghavan

Download Sample Code

This article shows how to watermark PDFs using the open source PDF generation library iTextSharp, C#, and ASP.NET.

Often enough, Web Applications use PDF documents which may be printable versions of pages, custom forms, manuals etc. When the document consists of critical or sensitive information, the pages are watermarked with the company logo or some other custom image file. There are some off-the-shelf commercial products which have this feature. This article looks at such an implementation using the open source PDF generation library iTextSharp, C#, and ASP.NET.


For detail, please visit http://dotnetslackers.com/articles/aspnet/WatermarkingPDFDocumentsUsingHttpHandlers.aspx

PdfReader not opened with owner password

Wednesday, December 12th, 2007 by rubypdf

I search the source code of itext-src2.0.6 and iTextSharp-4.0.7 with the keyword “PdfReader not opened with owner password”, and get the following result,

itext-src-2.0.6
[F:\soft\0710\itext\itext-src-2.0.6\com\lowagie\text\pdf\PdfCopyFieldsImp.java]
Line 115 : throw new IllegalArgumentException(”PdfReader not opened with owner password”);
[F:\soft\0710\itext\itext-src-2.0.6\com\lowagie\text\pdf\PdfReaderInstance.java]
Line 85 : throw new IllegalArgumentException(”PdfReader not opened with owner password”);
[F:\soft\0710\itext\itext-src-2.0.6\com\lowagie\text\pdf\PdfStamperImp.java]
Line 103 : throw new IllegalArgumentException(”PdfReader not opened with owner password”);

itextsharp-4.0.7
F:\soft\0712\itextsharp-4.0.7\iTextSharp\text\pdf\PdfCopyFieldsImp.cs(102): throw new ArgumentException(”PdfReader not opened with owner password”);
F:\soft\0712\itextsharp-4.0.7\iTextSharp\text\pdf\PdfReaderInstance.cs(86): throw new ArgumentException(”PdfReader not opened with owner password”);
F:\soft\0712\itextsharp-4.0.7\iTextSharp\text\pdf\PdfStamperImp.cs(92): throw new ArgumentException(”PdfReader not opened with owner password”);

Why do I get the exception ‘PdfReader not opened with owner password’

Wednesday, December 12th, 2007 by rubypdf

When I tried to decrypt a owner password protected PDF(version 1.6) with the last version of itext yesterday, I got the exception, “PdfReader not opened with owner password”, then I tried to use my native version pdfdecrypt.exe(base on iText 1.46) and pdftk , it said the PDF version does not supports. so I had to google the result, then I got the answer,

Paulo Soares said,
From iText version 2.0.3 and iTextSharp 4.0.4 the password restrictions are enforced by the library instead of passing that responsability to the developer. Using PdfStamper or importing pages in PdfStamper, PdfCopy and PdfWriter will throw an exception if the PDF was not opened with the owner password.

then I tried iText 2.0.2, it works.

btw, I also find another solution from PDFSharp, and I notice a very interesting comment,

PDFsharp doesn’t try to protect the document because this make little sence for an open source library.

so why PdfReader try to protect the PDF?