Adding form fields and encrypt PDF (in one go)

32 Views Asked by At

I want to add several (acro) form fields to a pdf and afterwards encrypt it. Each single operation does work however if I do both I get the following error:

Content was already written to the output.

The Code in the PdfStamper checks (stamper.isContentWritten()) whether something was already written to the body, which obviously was the case when adding the form field annotation. Found the following code:

if (!annot.isUsed()) {
    annot.setUsed();
    addToBody(annot, annot.getIndirectReference());
}

Is there a way to do both with an existing instance of the PdfWriter/Stamper or do I have write out the enriched document and re-initialize the itext/openPDF Processor again to encrypt it?

0

There are 0 best solutions below