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.