Set or update title, author, subject, keywords, and custom fields in the PDF Info dictionary and the XMP metadata stream.
use pdfluent::{PdfDocument, PdfMetadata};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open("document.pdf")?;
doc.set_metadata(PdfMetadata {
title: Some("Q3 Financial Report".into()),
author: Some("Finance Team".into()),
subject: Some("Quarterly earnings summary".into()),
keywords: Some("finance, earnings, Q3 2025".into()),
..Default::default()
})?;
doc.save("document_updated.pdf")?;
Ok(())
}Open the PDF with a mutable binding. PDFluent loads the existing metadata so you can selectively update fields.
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open("report.pdf")?;PdfMetadata implements Default, so only the fields you set are updated. Fields left as None keep their existing values.
use pdfluent::PdfMetadata;
let meta = PdfMetadata {
title: Some("Annual Report 2025".into()),
author: Some("Acme Corp".into()),
keywords: Some("annual, report, 2025".into()),
..Default::default()
};Call set_metadata() to write the fields to the Info dictionary. The XMP stream is updated automatically to stay in sync.
doc.set_metadata(meta)?;Use the individual setter methods if you only want to change one field.
doc.set_title("Revised Annual Report 2025")?;
doc.set_author("Acme Corp Communications")?;Call save() or save_as() to write the changes. The modification date is updated automatically.
doc.save("report_updated.pdf")?;
// or save to a new path:
doc.save_as("report_v2.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.