Overlay a logo or stamp image on every page of a PDF. Control position, size, opacity, and rotation.
use pdfluent::{PdfDocument, ImageWatermark, WatermarkPosition};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open("document.pdf")?;
let watermark = ImageWatermark::from_file("logo.png")?
.opacity(0.10)
.width_percent(40.0)
.position(WatermarkPosition::Center);
doc.add_image_watermark(&watermark)?;
doc.save("document_branded.pdf")?;
Ok(())
}Open the document with a mutable binding.
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open("brochure.pdf")?;PDFluent accepts PNG and JPEG files. PNG with an alpha channel is supported, so transparent logos blend cleanly.
use pdfluent::ImageWatermark;
let watermark = ImageWatermark::from_file("company_logo.png")?;Set the width as a percentage of the page width. The height is calculated automatically to preserve the image aspect ratio.
let watermark = watermark
.opacity(0.15) // 15% opacity
.width_percent(30.0) // 30% of page width
.rotation(0.0); // no rotationChoose from preset positions or provide exact coordinates in PDF points with WatermarkPosition::Custom(x, y).
use pdfluent::WatermarkPosition;
let watermark = watermark
.position(WatermarkPosition::BottomRight);Stamp all pages and write the result to disk.
doc.add_image_watermark(&watermark)?;
doc.save("brochure_branded.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.