JAVA add image watermark to PDF

This article will demonstrate how to use Spire.PDF for Java to add image watermark to PDF.

We need to load the image by the method loadFromFile() and then, set the PDF background image to be the image watermark and then set the background region for the image.

import com.spire.pdf.*;
import java.awt.geom.Rectangle2D;

public class watermark {

    public static void main(String[] args) {

        //Create a pdf document and load the sample document from file
        PdfDocument doc = new PdfDocument();
        //Get the first page
        PdfPageBase page = doc.getPages().get(0);  

        //Load the image and set it as background image

        //Set the background region
        Rectangle2D.Float rect = new Rectangle2D.Float();
        rect.setRect(280, 300, 150, 150);

        //Save pdf file


JAVA add image watermark to PDF