Reading Security Properties

Is it possible to read the security properties for an existing PDF file?

I am able to load the file as follows:

FileStream fsPDF = new FileStream(FileName, FileMode.Open);
Pdf PDF = new Pdf(fsPDF);

But PDF.Security is null.


This message was posted using Aspose.Live 2 Forum

Hi Lee,

I would like to share with you that you’re using Aspose.Pdf in your code; in fact, Aspose.Pdf only allows you to create new PDF files from scratch and you might set the security properties. However, Aspose.Pdf.Kit allows you to manipulate existing PDF files; that is, you can either set or get security privileges of an existing PDF file. Please use GetDocumentPrivilege method of the PdfFileInfo class; this method returns a DocumentPrivilege object which contains all the privileges applied to the PDF file. You can also find other security related operations allowed in Aspose.Pdf.Kit on this link.

I hope this helps. If you think it doesn’t satisfy your requirement then please elaborate it a little bit.

We’re sorry for the inconvenience and looking forward to help you out.
Regards

I have attempted to use the GetDocumentPrivilege class and it does not return the correct values. I am using version 3.9 of Aspose.PDF.Kit.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Here’s the code:

FileStream fs = new FileStream(filePath, FileMode.Open);

PdfFileInfo fi = new PdfFileInfo(fs);

DocumentPrivilege privilege = fi.GetDocumentPrivilege();

StringBuilder sb = new StringBuilder();

sb.AppendLine("AllowAssembly: " + Environment.NewLine + " " + privilege.AllowAssembly.ToString());

sb.AppendLine("AllowCopy: " + Environment.NewLine + " " + privilege.AllowCopy.ToString());

sb.AppendLine("AllowDegradedPrinting: " + Environment.NewLine + " " + privilege.AllowDegradedPrinting.ToString());

sb.AppendLine("AllowFillIn: " + Environment.NewLine + " " + privilege.AllowFillIn.ToString());

sb.AppendLine("AllowModifyAnnotations: " + Environment.NewLine + " " + privilege.AllowModifyAnnotations.ToString());

sb.AppendLine("AllowModifyContents: " + Environment.NewLine + " " + privilege.AllowModifyContents.ToString());

sb.AppendLine("AllowPrint: " + Environment.NewLine + " " + privilege.AllowPrint.ToString());

sb.AppendLine("AllowScreenReaders: " + Environment.NewLine + " " + privilege.AllowScreenReaders.ToString());

lblProperties.Text = sb.ToString();

}

This does not return the correct properties of the file.

I have also tried using the filePath directly with the same results.

The intellisense for the properties do not show them to be get or set, but I do not get any error.

Thanks for your help.

Hi Lee,

Can you please download the latest version (Aspose.Pdf.Kit for .NET 4.6.0) and try with that? If it still doesn’t resolve your issue then please share the input PDF file with us, so we could test the issue using your particular scenario.

We’re sorry for the inconvenience and looking forward to help you out.
Regards,

I tried the 4.6 version and get the same result.

I have attached the file I have been testing. In Acrobat this file is shown not to allow copying, yet use of the Aspose.PDF.Kit shows that copying is allowed.

What I am ultimately attempting to accomplish is to determine whether a file is locked when a user uploads a PDF. At that point I intend to alert the user that the file must be unlocked.

Thanks for your help.

Hi Lee,

I have reproduced this problem at my end and logged it as PDFKITNET-18831 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as 18831) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.