Apply text watermarks, image overlays, and stamps to single pages or entire documents. Batch watermark with per-document variable data.
use pdfluent::{Sdk, watermark::{WatermarkOptions, TextWatermark, Position}};
fn main() -> pdfluent::Result<()> {
let sdk = Sdk::new()?;
let doc = sdk.open("contract.pdf")?;
let watermark = TextWatermark::builder()
.text("CONFIDENTIAL")
.font_size(72.0)
.font_family("Helvetica")
.opacity(0.15)
.rotation_degrees(45.0)
.color_rgb(0.5, 0.0, 0.0)
.position(Position::Center)
.apply_to_all_pages(true)
.build();
let opts = WatermarkOptions::builder()
.text_watermark(watermark)
.build();
let stamped = doc.add_watermark(opts)?;
stamped.save("contract_watermarked.pdf")?;
println!("Watermarked {} pages", stamped.page_count());
Ok(())
}Run cargo add pdfluent@1.0.0-beta.5 to get started.
Render text directly into the PDF content stream at any font size, rotation, and opacity. Font is embedded in the output document. Supports any TrueType or OpenType font you provide, not just the 14 standard PDF fonts.
Place a PNG or JPEG image over or under page content. Control position, scale, and opacity. The image is embedded once and referenced from each page, keeping file size small for multi-page documents.
Position a watermark at center, corners, or at an arbitrary x/y coordinate in PDF user space. Tile mode repeats the watermark across the page at a configurable grid spacing. Diagonal mode automatically rotates text to span the full page diagonal.
Apply watermarks to all pages, to a specific page range, or to pages matching a condition (e.g., odd pages, pages above a certain index). Skip the cover page by excluding page 0 from the range.
Stamp each document with recipient-specific text by passing a callback that returns watermark text per document path. Process thousands of PDFs in parallel: each gets its own stamp (e.g., recipient name, date, copy number) without manual iteration.
Remove watermarks from documents you own by identifying watermark content layers or form XObjects by name. The removal API targets only the watermark layer and leaves the rest of the content stream intact.