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

Free Support Forum - aspose.com

PdfFileSecurity - What are we doing wrong?

We are trying to make a PDF file on disk non-editable.

Our code is:

Dim fileSecurity As PdfFileSecurity = New PdfFileSecurity(inFile, outFile)
fileSecurity.SetPrivilege(PdfPrivilege.ModifyContents)

After that, still editable. So we tried:



Dim fileSecurity As PdfFileSecurity = New PdfFileSecurity(inFile, outFile)

fileSecurity.SetPrivilege(Not PdfPrivilege.ModifyContents)

Still editable.

What are we missing? Does the SetPrivilege() method save the document? The sample code would suggest it does.

Hello Patrick,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Plesae use PdfFileSecurity.setPrivilege(DocumentPrivilege) instead of PdfFileSecurity.setPrivilege(PdfPrivilege) as Aspose.Pdf.Kit not supports PdfPrivilege method.

SetPrivilege() method sets Pdf file security without being encrypted and saves the copy of input pdf file. Please try the following code snippet if you want the users to only view the document and don’t want them to change the contents.

string inFile = @"C:\pdftest\FormFields_output.pdf"; //The TestPath may be re-assigned.
string outFile = @"C:\pdftest\sample_FormFields_output.pdf"; //The TestPath may be re-assigned.

PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
fileSecurity.SetPrivilege( DocumentPrivilege.ScreenReaders);