Expand description
PDF manipulation: pages, encryption, watermarks, text replacement, and more.
All operations work on lopdf::Document objects, which can be loaded
from a file (Document::load) or obtained from another pdf-manip call.
Most functions return Result<_, ManipError>.
This crate’s public API is panic-free. Errors are returned as Result<T, ManipError>.
Note on page numbering: all page indices throughout this crate are 1-based to match PDF conventions.
§Quick Start
use lopdf::Document;
use pdf_manip::pages;
use pdf_manip::encrypt::{EncryptionAlgorithm, encrypt_and_save, EncryptConfig, Permissions};
// Merge two PDFs.
let mut merged = pages::merge(&["a.pdf", "b.pdf"]).unwrap();
merged.save("merged.pdf").unwrap();
// Extract pages 1–3 from a document.
let doc = Document::load("report.pdf").unwrap();
let mut subset = pages::extract_pages(&doc, &[1, 2, 3]).unwrap();
subset.save("pages_1_to_3.pdf").unwrap();
// Encrypt with AES-256.
let mut doc = Document::load("sensitive.pdf").unwrap();
let cfg = EncryptConfig {
owner_password: b"owner_pw".to_vec(),
user_password: b"user_pw".to_vec(),
algorithm: EncryptionAlgorithm::Aes256,
permissions: Permissions::allow_all(),
};
let out = std::fs::File::create("sensitive_enc.pdf").unwrap();
encrypt_and_save(&mut doc, &cfg, out).unwrap();§Modules
Functions are accessed through their sub-modules rather than re-exports:
| Module | Operations |
|---|---|
pages | merge, split, extract_pages, delete_pages, insert_pages, rotate_pages |
encrypt | encrypt_document, remove_encryption, AES-256 / RC4 |
watermark | Text and image watermarks |
optimize | Stream compression, object deduplication |
bookmarks | Read and write document outline / bookmarks |
text_replace | Search-and-replace in content streams |
header_footer | Add headers and footers to pages |
Re-exports§
pub use content_editor::ContentEditor;pub use content_editor::GraphicsSnapshot;pub use content_editor::GraphicsStateTracker;pub use error::ManipError;pub use error::Result;pub use text_run::FontMap;pub use text_run::TextRun;
Modules§
- bookmarks
- PDF bookmarks (outlines) — read, create, modify, import/export.
- cff_
append - Append a single blank glyph to a CFF (Type1C) font program.
- clock
- Wall-clock time that is safe on wasm32, where
SystemTime::now()panics. Wall-clock time that works on every target we ship to. - content_
editor - Content stream round-trip: parse, modify, serialize.
- downsample
- Image downsampling for PDF optimization.
- embed_
font - Embed a TrueType font and make it usable from page content.
- encrypt
- PDF encryption, decryption, and password protection.
- error
- Error types for
pdf-manipoperations. - font_
subset - Font subsetting for embedded PDF fonts.
- header_
footer - Headers, footers, and Bates numbering for PDF pages.
- image_
edit - Edit images that are already placed on a page: list them, move or resize one, swap its picture, remove it.
- image_
insert - Insert JPEG/PNG images into PDF pages as Image XObjects.
- optimize
- PDF compression and optimization.
- pages
- Page manipulation: merge, split, insert, delete, rearrange, rotate, crop.
- pdfa
- PDF/A conversion: the whole pipeline, in one place.
- pdfa_
cleanup - PDF/A cleanup: remove JavaScript, EmbeddedFiles, transparency, and other PDF/A-incompatible elements.
- pdfa_
colorspace - PDF/A color space normalization and OutputIntent management.
- pdfa_
fixups - Supplementary PDF/A compliance fixes.
- pdfa_
fonts - PDF/A font embedding and subsetting.
- pdfa_
structure - PDF/A structure and hierarchy fixes.
- pdfa_
subset - Conservative glyph-preserving font storage compaction.
- pdfa_
xmp - PDF/A XMP metadata repair and generation.
- pdfua
- PDF/UA remediation helpers.
- text_
edit - Layout-aware text editing: find → stage → commit (Phase 1B engine).
- text_
replace - Text replacement in PDF content streams (legacy convenience API).
- text_
run - Text run identification from content streams with CMap-aware decoding.
- text_
style - Text-run style mutations: bold and italic via embedded font variant swaps.
- unicode_
font - Embedding a caller-supplied Unicode font, so a replacement can contain characters the document’s own fonts have no glyph for. Embedding a caller-supplied Unicode font as a Type0 composite font, so a replacement can contain characters the original font has no glyph for.
- watermark
- Text and image watermarking for PDF pages.