Adding a "DRAFT" watermark to every page of a two-page document that is PDF/A-3a and PDF/UA-1.
Example_45.pdf — the PDF this example creates.
package examples;
import java.io.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;
/**
* Example_45.java
* This example adds a "DRAFT" watermark to every page of a two-page
* document that is PDF/A-3a and PDF/UA-1. The watermark is drawn first, so the
* text of the page is drawn over it.
*/
public class Example_45 {
public Example_45() throws Exception {
PDF pdf = new PDF(
new BufferedOutputStream(new FileOutputStream("Example_45.pdf")),
Compliance.PDF_A_3A_UA_1);
pdf.setTitle("A Draft, Archived as PDF/A-3a and PDF/UA-1");
Font f1 = new Font(pdf, IBMPlexSans.Regular);
Font f2 = new Font(pdf, IBMPlexSans.SemiBold);
Font f3 = new Font(pdf, IBMPlexSans.Bold);
String[] titles = {
"Project Proposal",
"Budget and Schedule",
};
String[] texts = {
"This proposal describes a new reporting service that creates invoices, "
+ "statements and delivery notes as PDF documents. The documents are "
+ "archived as PDF/A-3a, so they can be opened and printed exactly "
+ "the same way for many years.\n\n"
+ "The watermark tells every reader that this is a draft. It is drawn "
+ "in light gray behind the text, at an angle from the bottom left "
+ "corner to the top right corner of the page.",
"The service will be built in three phases over six months. The first "
+ "phase delivers invoices, the second statements, and the third "
+ "delivery notes.\n\n"
+ "The budget and the schedule will be final once the proposal is "
+ "approved. Until then, every page of this document is marked as a draft.",
};
for (int i = 0; i < titles.length; i++) {
Page page = new Page(pdf, A4.LANDSCAPE);
// The watermark is drawn before the content of the page.
f3.setSize(120f);
page.addWatermark(f3, "DRAFT");
TextLine title = new TextLine(f2, titles[i]);
title.setStructureType(StructElem.H1);
title.setFontSize(28f);
title.setLocation(70f, 100f);
title.drawOn(page);
TextBlock textBlock = new TextBlock(f1, texts[i]);
textBlock.setFontSize(14f);
textBlock.setLineSpacing(1.5f);
textBlock.setLocation(70f, 130f);
textBlock.setWidth(page.getWidth() - 140f);
textBlock.drawOn(page);
TextLine footer = new TextLine(f1, "Page " + (i + 1) + " of " + titles.length);
footer.setFontSize(10f);
footer.setTextColor(Color.dimgray);
footer.setLocation(70f, page.getHeight() - 40f);
footer.drawOn(page);
}
pdf.complete();
}
public static void main(String[] args) throws Exception {
long time0 = System.currentTimeMillis();
new Example_45();
long time1 = System.currentTimeMillis();
System.out.printf("Example_45 => %4d ms%n", time1 - time0);
}
} // End of Example_45.java
©2026 PDFjet Software.