Draw text or an image stamp at a fixed position on every page, with configurable opacity, size, and rotation.
use pdfluent::{Document, stamp::{TextStamp, StampPosition}};
fn main() -> pdfluent::Result<()> {
let mut doc = Document::open("input.pdf")?;
let stamp = TextStamp::new("CONFIDENTIAL")
.position(StampPosition::Center)
.font_size(48.0)
.opacity(0.25)
.rotation(45.0)
.color(pdfluent::color::Color::rgb(0.8, 0.0, 0.0));
doc.apply_stamp(&stamp)?;
doc.save("stamped.pdf")?;
Ok(())
}Stamps are applied to page content streams. Open the file for mutation.
let mut doc = Document::open("input.pdf")?;TextStamp::new takes the stamp text. Chain builder methods for position, size, color, rotation, and opacity.
use pdfluent::stamp::{TextStamp, StampPosition};
let stamp = TextStamp::new("DRAFT")
.position(StampPosition::Center)
.font_size(72.0)
.opacity(0.15)
.rotation(45.0);doc.apply_stamp() iterates all pages and appends the stamp as a graphics operator block in each content stream.
doc.apply_stamp(&stamp)?;Use apply_stamp_to_page to target individual pages.
// Stamp only pages 1 and 3 (zero-indexed: 0, 2)
doc.apply_stamp_to_page(&stamp, 0)?;
doc.apply_stamp_to_page(&stamp, 2)?;Load a PNG or JPEG and use ImageStamp to overlay it on each page.
use pdfluent::stamp::{ImageStamp, StampPosition};
let image_data = std::fs::read("stamp_logo.png")?;
let img_stamp = ImageStamp::from_png(&image_data)
.position(StampPosition::BottomRight)
.width_pt(120.0)
.opacity(0.6);
doc.apply_stamp(&img_stamp)?;
doc.save("stamped.pdf")?;No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.