We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pdf Security not applied to pdf doc

Hi I am using following code to apply security to the pdf document. The generated pdf has the security as attached. Please suggest what is wrong in the code.

Aspose.Pdf.Kit.DocumentPrivilege pdfPrevilege = Aspose.Pdf.Kit.DocumentPrivilege.ForbidAll;

//pdfPrevilege.AllowPrint = !_documentExportConfiguration.PdfSecuritySetting.IsPrintingAllowed;
//pdfPrevilege.AllowModifyContents = !_documentExportConfiguration.PdfSecuritySetting.IsChangeDocument;

//pdfPrevilege.AllowScreenReaders = !_documentExportConfiguration.PdfSecuritySetting.IsSelectTextGraphics;
//pdfPrevilege.AllowCopy = !_documentExportConfiguration.PdfSecuritySetting.IsSelectTextGraphics;
//pdfPrevilege.AllowAssembly = !_documentExportConfiguration.PdfSecuritySetting.IsSelectTextGraphics;

//pdfPrevilege.AllowFillIn = !_documentExportConfiguration.PdfSecuritySetting.IsAddOrChangeNotes;
//pdfPrevilege.AllowModifyAnnotations = !_documentExportConfiguration.PdfSecuritySetting.IsAddOrChangeNotes;
//pdfPrevilege.AllowModifyContents = !_documentExportConfiguration.PdfSecuritySetting.IsAddOrChangeNotes;

PdfFileSecurity fileSecurity = new PdfFileSecurity(tempFileName, sourceFile);

//Calling EncryptFile method to encrypt the PDF document
fileSecurity.SetPrivilege(userPassword, ownersPassword, pdfPrevilege);

Hi,

Please try to use our latest merged version – Aspose.Pdf for .NET 6.1.0. If it still doesn’t resolve your issue then please share the input PDF file with us, so we could investigate the issue at our end. You’ll be updated with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Hi

Thank you for the suggestions. I updated Aspose.Pdf.dll to latest version.

I tried using PdfPrivilege and DocumentPrevilege but I see some security setting issue.

PdfFileSecurity fileSecurity = new PdfFileSecurity(@"C:\\SecurityTest.pdf", @"C:\\SecurityTest1.pdf");
//Aspose.Pdf.Kit.PdfPrivilege previlege = 0;
Aspose.Pdf.Kit.DocumentPrivilege previlege = Aspose.Pdf.Kit.DocumentPrivilege.ForbidAll;
//fileSecurity.SetPrivilege("test1", "test1", previlege);
fileSecurity.EncryptFile("test1", "test1", previlege, true);PdfFileSecurity fileSecurity = new PdfFileSecurity(@"C:\\SecurityTest.pdf", @"C:\\SecurityTest1.pdf");
//Aspose.Pdf.Kit.PdfPrivilege previlege = 0;
Aspose.Pdf.Kit.DocumentPrivilege previlege = Aspose.Pdf.Kit.DocumentPrivilege.ForbidAll;
//fileSecurity.SetPrivilege("test1", "test1", previlege);
fileSecurity.EncryptFile("test1", "test1", previlege, true);

I have attached the generated pdf and the screenshot of permissions. even though all permissions are denied, I am able to select the content from pdf, print the pdf etc.

Your help is appreciated.

Hi

Did you get a chance to look at this issue? if you need any more information please let me know. your help is appreciated.

Hi,

Please use different values when setting user and owner password. When you set same values for user and owner password, file is always opened with owner password and in owner mode all the permissions are allowed automatically.

I hope this helps. If you still find any issue, please do let us know.
Regards,