Issue opening a PDF document

When we try create a Document object for certain (non password protected) PDF’s with the permissions in the attached picture, it fails with a " Permissions check failed (invalid Perms literals" error.

The PDF’s open fine in a browser, and we only need to read/copy the content and not edit it, and that should be possible from the permissions.

I have looked to see if there is a way to create the Document object as read only, but I can not find a way.

Any help would be greatly appreciated.

image.png (24.6 KB)

@gregglinnellciv

Cause

The error “Permissions check failed (invalid Perms literals)” typically occurs when the PDF document has certain permissions that are not compatible with the operations you are trying to perform. Even if the PDF opens fine in a browser, it may have restrictions that prevent certain actions when accessed programmatically.

Solution

To address this issue, you can try the following steps:

  1. Check Document Permissions: Ensure that the PDF allows content extraction. You can check the permissions using the DocumentPrivilege class in Aspose.PDF.

  2. Use PdfFileSecurity: If the document has restrictive permissions, you can use the PdfFileSecurity class to modify the permissions of the PDF. This allows you to set the necessary privileges for reading and copying content.

Code

Here’s a sample code snippet to check and set permissions:

using Aspose.Pdf;
using Aspose.Pdf.Facades;

// Load the PDF document
string pdfPath = "path/to/your/document.pdf";
using (PdfFileSecurity fileSecurity = new PdfFileSecurity())
{
    fileSecurity.BindPdf(pdfPath);

    // Check current privileges
    DocumentPrivilege privileges = fileSecurity.GetPrivilege();
    if (!privileges.AllowCopy)
    {
        // Set new privileges
        privileges.AllowCopy = true;
        fileSecurity.SetPrivilege(privileges);
    }

    // Save the modified document
    fileSecurity.Save("path/to/your/modified_document.pdf");
}

Next Steps

  1. Run the above code to modify the permissions of your PDF document.
  2. After adjusting the permissions, try to create the Document object again.
  3. If the issue persists, check the PDF structure for any corruption or unusual settings.

Please proceed with these steps and let me know if you encounter any further issues. I’m here to help!

Sources:
[1]: Set Privileges on PDF|Aspose.PDF for .NET

GetPrivilege() does not work, it says pdffilesecurity does not contain a definition for it.

Regards

Also as you can see in the original image, it does have the content copying allowed.

I tried just creating a privilege object and then assign it to the filesecurity, but that two errors with: Permissions check failed (invalid Perms literals).’

This appears to be a bug. I downgraded to the previous version that we were using (22.2) and that did not have the problem, the document object created no problem.

Now that we are running version 25.6.1, the problem is occuring.

I have tracked back and the version of Aspose.PDF that it broke on was 24.11.0

@gregglinnellciv

Would you please share your sample PDF document along with the sample PDF file for our reference? We will test the scenario in our environment and address it accordingly.

Unfortunately I can not share the specific PDF file with you as it is a legal document from one of our clients which contains sensitive information on one of their clients,

I can tell you that it was an Excel documents which was saved as a PDF and secured using PDF Architect to only give it the permissions detailed in the image from my original post.

@gregglinnellciv

Would you please try using below code snippet at your end and see if it helps:

var pdfdocument = new Document(dataDir + "input.pdf");
DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;
privilege.ChangeAllowLevel = 0;
privilege.AllowCopy = true;
PdfFileSecurity fileSecurity = new PdfFileSecurity(pdfdocument);
fileSecurity.SetPrivilege(privilege);
fileSecurity.Save(dataDir + "output.pdf");

That fails as soon as it hits the new Document part. That’s the problem we are having with these documents in our own software, is the perm error occurs when doing new Document.

@gregglinnell

Looks like the document has some kind of permissions preset that we need to investigate and see if we can implement some functionality in the API to handle it accordingly. Therefore, we need the document and you can please share it through private message in case it is confidential. It will stay between you and Aspose only. We erase documents from our system after testing is done. You can send a private message by clicking on username and pressing Blue Message button.