AssembleDocument Permission

Hi,
Im trying to set permission for pdf my code is
if (pdfDoc == null||(string.IsNullOrEmpty(userPassword) && string.IsNullOrEmpty(ownerPassword)))
return;
Aspose.Pdf.Permissions permissions =
Aspose.Pdf.Permissions.PrintDocument |
Aspose.Pdf.Permissions.ModifyContent |
Aspose.Pdf.Permissions.ExtractContent |
Aspose.Pdf.Permissions.ModifyTextAnnotations |
Aspose.Pdf.Permissions.FillForm |
Aspose.Pdf.Permissions.AssembleDocument |
Aspose.Pdf.Permissions.PrintingQuality;
if (!string.IsNullOrWhiteSpace(userPassword))
{
if (!printDocument)
permissions &= ~Aspose.Pdf.Permissions.PrintDocument;

if (!extractContent)
    permissions &= ~Aspose.Pdf.Permissions.ExtractContent;

if (!modifyContent)
    permissions &= ~Aspose.Pdf.Permissions.ModifyContent;

if (!assembleDocument)
    permissions &= ~Aspose.Pdf.Permissions.AssembleDocument;

if (!fillForm)
    permissions &= ~Aspose.Pdf.Permissions.FillForm;

if (!modifyTextAnnotations)
    permissions &= ~Aspose.Pdf.Permissions.ModifyTextAnnotations;

}
pdfDoc.Encrypt(
userPassword,
ownerPassword,
permissions,
CryptoAlgorithm.AESx256
);

here it is working for all permission except AssembleDocument. even if i set this to true but still in generated pdf protection property it showing not allowed for both admin and user password.

@Darshan06

Cause

You are experiencing an issue with the AssembleDocument permission not being applied correctly in your PDF document. This can occur if the permissions are not set properly or if there are conflicting settings in your code.

Solution

To ensure that the AssembleDocument permission is correctly applied, please verify the following:

  1. Check the Permissions Logic: Confirm that the logic for setting permissions is accurate. If assembleDocument is set to true, it should not be removed from the permissions.

  2. Use Correct Encryption Method: Ensure that you are using the appropriate encryption method and that the permissions are being passed correctly.

  3. Verify Passwords: Make sure that the user and owner passwords are different and correctly set. If they are the same or not set properly, it may lead to issues with permissions.

Code

Here’s a refined version of your code snippet to ensure the permissions are set correctly:

if (pdfDoc == null || (string.IsNullOrEmpty(userPassword) && string.IsNullOrEmpty(ownerPassword)))
    return;

Aspose.Pdf.Permissions permissions = 
    Aspose.Pdf.Permissions.PrintDocument |
    Aspose.Pdf.Permissions.ModifyContent |
    Aspose.Pdf.Permissions.ExtractContent |
    Aspose.Pdf.Permissions.ModifyTextAnnotations |
    Aspose.Pdf.Permissions.FillForm |
    Aspose.Pdf.Permissions.AssembleDocument |
    Aspose.Pdf.Permissions.PrintingQuality;

if (!string.IsNullOrWhiteSpace(userPassword))
{
    if (!printDocument)
        permissions &= ~Aspose.Pdf.Permissions.PrintDocument;

    if (!extractContent)
        permissions &= ~Aspose.Pdf.Permissions.ExtractContent;

    if (!modifyContent)
        permissions &= ~Aspose.Pdf.Permissions.ModifyContent;

    if (!assembleDocument)
        permissions &= ~Aspose.Pdf.Permissions.AssembleDocument;

    if (!fillForm)
        permissions &= ~Aspose.Pdf.Permissions.FillForm;

    if (!modifyTextAnnotations)
        permissions &= ~Aspose.Pdf.Permissions.ModifyTextAnnotations;
}

pdfDoc.Encrypt(
    userPassword,
    ownerPassword,
    permissions,
    CryptoAlgorithm.AESx256
);

Next Steps

  1. Test the Code: Execute the modified code and verify if the AssembleDocument permission is now allowed in the generated PDF.

  2. Check PDF Properties: After generating the PDF, examine the document properties to confirm that the permissions are set as expected.

  3. Review Documentation: If the issue persists, consult the Aspose documentation on setting permissions and encryption to ensure all requirements are met.

Please proceed with these steps and let me know if you need further assistance!

please give proper code you have give same code which i shared.

@Darshan06

Looks like you are trying to set the permissions for an existing PDF document. Can you please share same document for our reference as well so that we can test the scenario in our environment and address it accordingly.