128-bit encryption, no owner password
We have an application that is creating a 128-bit encrypted PDF without user or owner passwords. When performing a PdfCopy.GetImportPage method call, the GetImportPage method fails in version 4.1.1.0. This worked in version 3.1.6.0.
The error might stem from the following:
//this is the error being thrown because false is being returend from "IsOpenedWillFullPermissions".
internal PdfImportedPage GetImportedPage(int pageNumber) {
if (!reader.IsOpenedWithFullPermissions)
throw new ArgumentException("PdfReader not opened with owner password");
//this method returns false if encrypted and no password is supplied.
public bool IsOpenedWithFullPermissions {
get {
return !encrypted || ownerPasswordUsed;
}
}
//this is the calling code
Snippet one…
if (reportGuid != Guid.Empty)
{
SQLFileInfo inputInfo = new SQLFileInfo(reportGuid);
using (SQLFileStream inputStream = inputInfo.Open(System.IO.FileMode.Open))
{
reader = new PdfReader(inputStream, null);
if (copy == null)
{
doc = new Document(reader.GetPageSizeWithRotation(1));
copy = new PdfCopy(doc, outputStream);
doc.Open();
}
//copy the pages
CopyPages(copy, reader);
}
}
Snippet two…
private void CopyPages(PdfCopy copy, PdfReader reader)
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
//This is where the error happens
copy.AddPage(copy.GetImportedPage(reader, i));
}
}