Why do I get an error saying that "use of extended features is no longer available"?

Tags: usage rightsreader enablingappend modePdfStamperiText 5

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(
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
PdfContentByte over = stamper.getOverContent(1);
over.setFontAndSize(bf, 10);
over.setTextMatrix(107, 107);
over.showText("page updated");
This works for all PDFs, except for PDFs with forms. When I open a document after adding this text, I get a lengthy error message about reader extensions.

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:

  1. 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.

  2. Fill out the form in append mode. This will result in a bigger file size, but Reader enabling will be preserved.

Removing usage rights is done like this:

PdfReader reader = new PdfReader(old_file);
if (reader.hasUsageRights()) {
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(new_file));

Using iText in append mode is done like this:

PdfReader reader = new PdfReader(src);
PdfStamper stamper =
    new PdfStamper(reader, new FileOutputStream(dest), '\0', true);

Note the extra parameters in PdfStamper. They cause iText to preserve the original bytes of the file and avoid breaking the signature.

Extra remark: you are adding text the hard way. You'd make it easier on yourself if you'd use the ColumnText.showTextAligned() method to add text.