Hello,
I have the following function that I use to apply encryption and permissions to a PDF document:
public void addDocumentPrivilege(String documentState, Document pdfDocument, String objId) {
List<String> endStates = List.of("Effective", "Approved", "Superseded", "Obsolete", "Recorded");
if (endStates.stream().anyMatch(documentState::contains)) {
PdfFileSignature pdfSign = new PdfFileSignature(pdfDocument);
if (!pdfSign.isCertified()) {
// Set document privileges
DocumentPrivilege privilege = DocumentPrivilege.getForbidAll();
privilege.setAllowAssembly(false);
privilege.setAllowModifyAnnotations(true);
privilege.setAllowModifyContents(false);
privilege.setAllowPrint(true);
privilege.setPrintAllowLevel(2);
privilege.setAllowCopy(true);
// Apply privileges and encrypt the PDF
PdfFileSecurity fileSecurity = new PdfFileSecurity(pdfDocument);
fileSecurity.setPrivilege(privilege);
pdfDocument.encrypt("", objId, privilege, CryptoAlgorithm.RC4x128, false);
}
}
}
This code has been working correctly for a long time. However, when I process a PDF document with version 2.0, I receive the following exception:
Generate PDF error for file - 068WD00000BK9lZYAT.pdf
The error - The value of usePdf20 should be true in PDF 2.0.
Based on the error message, I modified the code to use AES-256 encryption and set the usePdf20 parameter to true:
pdfDocument.encrypt("", objId, privilege, CryptoAlgorithm.AESx256, true);
However, I still receive the exact same exception.
To isolate the issue, I also removed the usage of PdfFileSignature, PdfFileSecurity, and even the privilege configuration itself, but the exception still occurs whenever the input document is a PDF 2.0 file.
The problem appears to affect all PDF 2.0 documents, while the same code continues to work correctly for earlier PDF versions.
Could you please help me understand whether I am missing an additional step or configuration required for PDF 2.0 encryption support?
For reference:
- Aspose.PDF version: 25.8
- Input PDF version: 2.0
- Exception message: “The value of usePdf20 should be true in PDF 2.0”.
Thank you for your assistance.