Why do I get an error saying that "use of extended features is no longer available"?
What do I do when I get an error message about reader extensions.
I am stamping text on an existing PDF document using this code:
PdfReader reader = new PdfReader("/Users/simple-user/Downloads/acroform.pdf"); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream( "/Users/simple-user/Downloads/acroform2.pdf")); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte over = stamper.getOverContent(1); over.beginText(); over.setFontAndSize(bf, 10); over.setTextMatrix(107, 107); over.showText("page updated"); over.endText(); stamper.close();
Posted on StackOverflow on Jun 8, 2015 by IowA
Your diagnosis is wrong. The problem is not related to the presence of AcroForms. The problem is related to whether or not your document is Reader Enabled. Reader-enabling can only be done using Adobe software. It is a process that requires a digital signature using a private key from Adobe. When a valid signature is present, specific functionality (as defined in the usage rights when signing) is unlocked in Adobe Reader.
You change the content of such a PDF, hence you break the signature. Breaking this signature is what causes the ugly error message:
This document enabled extended features in Adobe Acrobat Reader DC. The document has been changed since it was created and use of extended features is no longer available. Please contact the author for the original version of this document.
There are two ways to avoid this error message:
Remove the usage rights. This will result in a form that is no longer Reader enabled. For instance: if the creator of the document allowed that the filled out form could be saved locally, this will no longer be possible after removing the usage rights.
Fill out the form in append mode. This will result in a bigger file size, but Reader enabling will be preserved.
Please take a look at the ReaderEnabledForm example.
Removing usage rights is done like this:
public void removeUsageRights(PdfDocument pdfDoc) {
PdfDictionary perms = pdfDoc.getCatalog().getPdfObject().getAsDictionary(PdfName.Perms);
if (perms == null) {
return;
}
perms.remove(new PdfName("UR"));
perms.remove(PdfName.UR3);
if (perms.size() == 0) {
pdfDoc.getCatalog().remove(PdfName.Perms);
}
}
Using iText in append mode is done like this:
PdfDocument pdfDoc = new PdfDocument(reader, new PdfWriter(dest), new StampingProperties().useAppendMode());
Click this link if you want to see how to answer this question in iText 5.