Encrypt PDF File and Set Privileges to Allow Content Copying and Content Copying for Accessibility Permissions

Hi,
Our requirement is we want to allow Content Copying and Content Copying for Accessibility while we are encrypting pdf file without password.

Our code snipped is

Aspose.Pdf.Document pdfSourceFile = new Aspose.Pdf.Document(inputFile);
Permissions Permission = new Permissions();
string password = string.Empty;
Permission = Permissions.PrintDocument | Permissions.ModifyContent | Permissions.ModifyTextAnnotations;
pdfSourceFile.Encrypt(password, null, Permission, CryptoAlgorithm.AESx128);’

In this case Content Copying and Content Copying for Accessibility are Not allowed.

Please help us on this matter.

@acassel002

I have worked over your requirements and like to request you to please try using below sample code in your environment to serve the purpose, and then share your kind feedback with us.

        //Open source document
        Document document = new Document(inputFile);
        
        
        //Allow all privileges on the document
        DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

        //Apply the copy privilege
        privilege.AllowCopy = true;

        //Set the desired privileges
        PdfFileSecurity fileSecurity = new PdfFileSecurity(document);
        fileSecurity.SetPrivilege(privilege);

        //Save resulting PDF document
        document.Save(outputFile);

Passing a null string to Encrypt method is not a better option because if the password is null or empty then it is replaced with a random string. Therefore, do not encrypt the file but set the privileges with SetPrivilege method.

I hope this will be helpful. Please let us know if you need any further assistance.