-1

I am watermarking pdf document using itext7 library. it is preserving layers and shows one of its signature invalid. I want to flatten the created document.

When i tried saving the document manually using Adobe print option, it flattens all signature and makes the document as valid document. Same functionality i want with java program.

Is there any way using java program, we can flatten pdf document?

KJ21
  • 63
  • 7
  • Which library are you using? – ram May 24 '21 at 19:23
  • @ram Probably [tag:itext7]. – Izruo May 24 '21 at 19:25
  • See if [this](https://stackoverflow.com/a/43615477/9689059) answers your question – ram May 24 '21 at 19:30
  • There is a built-in function to flatten in `PDFBox`. If you wanna do it the easy way, you can import this library just to flatten and continue your other operations with `itext7` – ram May 24 '21 at 19:33
  • 1
    @ram There also is a built-in function for flattening *form fields*, so the OP can use iText 7 throughout. The actual problem in [the answer you referenced](https://stackoverflow.com/a/43615477/9689059) is that there is not yet a method for flattening *arbitrary* annotations, in particular annotations that are not form field widgets. – mkl May 24 '21 at 19:37

1 Answers1

1

According to your tag selection you appear to be using iText 7 for Java.

How to flatten a PDF AcroForm form using iText 7 is explained in the iText 7 knowledge base example Flattening a form. The pivotal code is:

PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);

// If no fields have been explicitly included, then all fields are flattened.
// Otherwise only the included fields are flattened.
form.flattenFields();

pdfDoc.close();

(https://kb.itextpdf.com/home/it7kb/examples/flattening-a-form visited 2021-05-24)

mkl
  • 90,588
  • 15
  • 125
  • 265