How to add watermark in PDF using Apache PDFBox Overlay

48 views Asked by At

I am trying to add watermark to PDF. I am taking following two files as inputs:

  1. Original PDF file: To which needs to be added.
  2. Watermark PDF File: It is one page PDF which only contains watermark.

I am trying to combine those files in PDFBox Overlay to generate new document containing watermark in it.

PDDocument watermarkDoc = PDDocument.load(new File("..."));
//Assuming your empty document with watermark image in it.

        PDDocument realDoc = PDDocument.load(new File("..."));

        Overlay overlay = new Overlay();
        overlay.setInputPDF(realDoc);
        overlay.setDefaultOverlayPDF(watermarkDoc);
        PDDocument document = overlay.overlay(new HashMap<Integer, String>());
        document.save("...")); 

But when I try to open newly generated document in acrobat, though the watermark is displayed in the file, but Acrobat is not able to detect it. That is I am not able to perform any operation like update or delete watermark.

0

There are 0 answers