Add watermark in PDF using Apache PDFBox

Watermark can add a level of security to a PDF against content piracy. Watermarks can be added in PDF using the Overlay class provided by the PDFBox library.Lets see an example on how to add watermark in PDF using Apache PDFBox.

Important methods of the Overlay class:
1) setInputFile(String inputFile) Sets the file to be overlayed.

2) setInputPDF(PDDocument inputPDF) Sets the PDF to be overlayed.

3) setOverlayPosition(Overlay.Position overlayPosition) Sets the overlay position.

4) overlay(Map<Integer,String> specificPageOverlayFile) This will add overlays to a documents. The map conatins page numbers and the watermark image/pdf location.


We will take the following PDF file and add a watermark to it.
File without watermark

Add watermark in PDF using Apache PDFBox

Add watermark in PDF using Apache PDFBox

1. Apache PDFBox Offical

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn