DocumentPrivilege.AllowAssembly always seems to be false

Dear Aspose representative,

I am currently trialing your product Aspose.PDF for .NET. When querying document Permissions, it seems that the AllowAssembly property always returns false on my documents. These are pdf files with no Encryption or other Signatures, and no explicit permissions set, and in the reader that I use it correctly shows the document’s permissions (at least, it shows me the permissions I expect).

Is it possible I am incorrectly using your library? Also, it seems as though this topic may be related (they mention ticket PDFNET-46708):

I appreciate any response or advice you can give.

Here is a code sample of my usage:

private static bool CanAssemble(string filename) => 
    new PdfFileInfo(new Document(filename)).GetDocumentPrivilege().AllowAssembly;

It seems the following question may also be related:

@nchappell

I request you to share a sample PDF file where you expect the Document Assembly property as true.

So I went with an Example from ISO 32000-1:2008, specifically H.3 “Simple Text String Example.” Here is the code below, note that copy/paste may or may not incorrectly copy the xref table depending on your environment (due to space at the end).

%PDF-1.4
1 0 obj
<< /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >>>
endobj

2 0 obj
<< /Type /Outlines /Count 0 >>
endobj

3 0 obj
<< /Type /Pages /Kids [4 0 R] /Count 1 >>
endobj

4 0 obj
<< 
    /Type /Page /Parent 3 0 R /MediaBox [0 0 612 792] /Contents 5 0 R 
    /Resources << 
        /ProcSet 6 0 R /Font << /F1 7 0 R >> 
    >>
>>
endobj

5 0 obj
<< /Length 49 >>
stream
BT
/F1 24 Tf
100 100 Td
(Hello World) Tj
ET
endstream
endobj

6 0 obj
    [/PDF /Text]
endobj

7 0 obj
<<
    /Type /Font
    /Subtype /Type1
    /Name /F1
    /BaseFont /Helvetica
    /Encoding /MacRomanEncoding
>>
endobj

xref
0 8
0000000000 65536 n 
0000000000 00009 n 
0000000000 00081 n 
0000000000 00132 n 
0000000000 00194 n 
0000000000 00369 n 
0000000000 00474 n 
0000000000 00511 n 

trailer
<< /Size 7 /Root 1 0 R >>

startxref
650
%%EOF

Actually, I have the same issue with the PdfFileInfo.IsPdfFile property: it always returns false. Is there any chance you guys could provide an example of a pdf file in which the DocumentPrivilege.AllowAssembly and PdfFileInfo.IsPdfFile are true?

@nchappell

I have checked properties of many PDF files and all of them have Document Assembly property set as “Not Allowed”. For IsPdfFile property, all valid PDF files return true, as with following code and file:

PdfFileInfo pdfFileInfo = new PdfFileInfo(dataDir + "Sample (8).pdf");
bool info = pdfFileInfo.IsPdfFile;

Sample (8).pdf (1.4 KB)

Therefore? In the sample you’ve sent me, PdfFileInfo.GetDocumentPrivilege().AllowAssembly is false, however I don’t see why it should be. According to PDF 32000-1:2008:

12.8.4 Permissions
The Perms entry in the document catalogue shall specify a permissions dictionary
… For a permission to be actually granted for a document, it shall be allowed by each permission handler that is present in the permissions dictionary as well as by the security handler.

7.6 Encryption
7.6.1 General
…Encryption-related information shall be stored in a documents encryption dictionary, which shall be the Encrypt entry in the document’s trailer dictionary. The absence of this entry from the trailer dictionary means that a conforming reader shall consider the document to be not encrypted.

Here is the Catalog of the document you sent me:

<</Type/Catalog/Version/1.7/Pages 3 0 R/Outlines 2 0 R/Metadata 11 0 R>>

And here is the trailer:

<</Root 1 0 R/Info 4 0 R/ID[<38312D37392D38362D41352D45352D36><38312D37392D38362D41352D45352D36>]/Size 12>>

As you can see, the trailer specifies no Perms entry, and there is no Encrypt entry in the Catalog. Therefore the requirements for all permissions to be allowed are fulfilled (vacuously).

Also, I’ve found an issue with the PdfFileInfo.IsPdfFile property. Consider the following code:

var path = @"C:\Users\nchappell\Downloads\Sample (8).pdf"

bool isValid;
bool canAssemble;
Document document = new Document(path);

PdfFileInfo pdfFileInfo = new PdfFileInfo(document);
isValid = pdfFileInfo.IsPdfFile;
canAssemble = pdfFileInfo.GetDocumentPrivilege().AllowAssembly;
Console.WriteLine($"CanAssemble: {canAssemble}, IsValid: {isValid}");

pdfFileInfo = new PdfFileInfo(path);
isValid = pdfFileInfo.IsPdfFile;
canAssemble = pdfFileInfo.GetDocumentPrivilege().AllowAssembly;
Console.WriteLine($"CanAssemble: {canAssemble}, IsValid: {isValid}");

The output I get is:

CanAssemble: False, IsValid: False
CanAssemble: False, IsValid: True

It seems that the PdfFileInfo object behaves differently when constructed from a Document or string. I don’t know if this is a bug, but the behavior is either confusing or subtle, and documenting this discrepancy would probably have been useful in my case.

@nchappell

Aspose.PDF mimics the behavior of Acrobat Adobe Reader and you can check from the properties tab about Document Assembly like attached snapshot. Adobe.PNG (6.5 KB)

For the issue with IsPdfFile, a ticket with ID PDFNET-50660 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thank you for the information.