Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Adding watermark to your PDF using Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.06k
    Comment on it

    Hi there,

    In this blog we will see how to add watermark images to our PDF files using Java.  Watermarks have been used to discourage counterfeiting. To generate watermarked PDFs we need an additional itext.jar file to be included in our class path which can be downloaded from here.


    Java code for add watermark to our PDF

    import com.lowagie.text.Image;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfStamper;
    public class AddWatermarkImageToPDFFile {
    	public static void main(String[] args) {
    		try {
    			PdfReader reader = new PdfReader("input.pdf");
    			int n = reader.getNumberOfPages();
    			PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
    			int i = 0;
    			PdfContentByte under;
    			Image img = Image.getInstance("images.png");
    			img.setAbsolutePosition(50, 300);
    			while (i < n) {
    				under = stamp.getUnderContent(i);
    		} catch (Exception de) {


    Our PDF before adding watermark


    PDF after adding watermark


    Thanks :)

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: