pdf_manip/lib.rs
1#![warn(missing_docs)]
2//! PDF manipulation: pages, encryption, watermarks, text replacement, and more.
3//!
4//! All operations work on [`lopdf::Document`] objects, which can be loaded
5//! from a file (`Document::load`) or obtained from another `pdf-manip` call.
6//! Most functions return [`Result<_, ManipError>`].
7//!
8//! This crate's public API is panic-free. Errors are returned as `Result<T, ManipError>`.
9//!
10//! **Note on page numbering:** all page indices throughout this crate are
11//! **1-based** to match PDF conventions.
12//!
13//! # Quick Start
14//!
15//! ```no_run
16//! use lopdf::Document;
17//! use pdf_manip::pages;
18//! use pdf_manip::encrypt::{EncryptionAlgorithm, encrypt_and_save, EncryptConfig, Permissions};
19//!
20//! // Merge two PDFs.
21//! let mut merged = pages::merge(&["a.pdf", "b.pdf"]).unwrap();
22//! merged.save("merged.pdf").unwrap();
23//!
24//! // Extract pages 1–3 from a document.
25//! let doc = Document::load("report.pdf").unwrap();
26//! let mut subset = pages::extract_pages(&doc, &[1, 2, 3]).unwrap();
27//! subset.save("pages_1_to_3.pdf").unwrap();
28//!
29//! // Encrypt with AES-256.
30//! let mut doc = Document::load("sensitive.pdf").unwrap();
31//! let cfg = EncryptConfig {
32//! owner_password: b"owner_pw".to_vec(),
33//! user_password: b"user_pw".to_vec(),
34//! algorithm: EncryptionAlgorithm::Aes256,
35//! permissions: Permissions::allow_all(),
36//! };
37//! let out = std::fs::File::create("sensitive_enc.pdf").unwrap();
38//! encrypt_and_save(&mut doc, &cfg, out).unwrap();
39//! ```
40//!
41//! # Modules
42//!
43//! Functions are accessed through their sub-modules rather than re-exports:
44//!
45//! | Module | Operations |
46//! |---|---|
47//! | [`pages`] | `merge`, `split`, `extract_pages`, `delete_pages`, `insert_pages`, `rotate_pages` |
48//! | [`encrypt`] | `encrypt_document`, `remove_encryption`, AES-256 / RC4 |
49//! | [`watermark`] | Text and image watermarks |
50//! | [`optimize`] | Stream compression, object deduplication |
51//! | [`bookmarks`] | Read and write document outline / bookmarks |
52//! | [`text_replace`] | Search-and-replace in content streams |
53//! | [`header_footer`] | Add headers and footers to pages |
54
55// Copyright (c) 2026 Innovation Trigger B.V.
56//
57// PDFluent is available under two licences, at your option: the GNU AGPLv3, or
58// the PDFluent Commercial Licence. See the LICENSE file in this repository --
59// that file travels with the copy you received, which a URL does not.
60
61pub mod bookmarks;
62pub mod cff_append;
63/// Wall-clock time that is safe on wasm32, where `SystemTime::now()` panics.
64pub mod clock;
65#[cfg(all(feature = "pdfa-convert", feature = "font-subset"))]
66pub(crate) mod cmap_codes;
67pub mod content_editor;
68#[cfg(feature = "image-insert")]
69pub mod downsample;
70pub mod embed_font;
71pub(crate) mod encoding_utils;
72pub mod encrypt;
73pub mod error;
74pub(crate) mod flate_decode;
75#[cfg(feature = "font-subset")]
76pub mod font_subset;
77pub mod header_footer;
78#[cfg(feature = "image-insert")]
79pub mod image_edit;
80#[cfg(feature = "image-insert")]
81pub mod image_insert;
82mod inline_image;
83pub mod optimize;
84pub mod pages;
85#[cfg(feature = "pdfa-convert")]
86pub mod pdfa;
87#[cfg(feature = "pdfa-convert")]
88pub mod pdfa_cleanup;
89#[cfg(feature = "pdfa-convert")]
90pub mod pdfa_colorspace;
91#[cfg(feature = "pdfa-convert")]
92pub mod pdfa_fixups;
93#[cfg(feature = "pdfa-convert")]
94pub mod pdfa_fonts;
95#[cfg(feature = "pdfa-convert")]
96pub(crate) mod pdfa_repair;
97#[cfg(feature = "pdfa-convert")]
98pub mod pdfa_structure;
99#[cfg(all(feature = "pdfa-convert", feature = "font-subset"))]
100pub mod pdfa_subset;
101#[cfg(feature = "pdfa-convert")]
102mod pdfa_text_geometry;
103#[cfg(feature = "pdfa-convert")]
104pub mod pdfa_xmp;
105pub mod pdfua;
106pub mod text_edit;
107pub mod text_replace;
108pub mod text_run;
109pub mod text_style;
110/// Embedding a caller-supplied Unicode font, so a replacement can contain
111/// characters the document's own fonts have no glyph for.
112#[cfg(feature = "font-subset")]
113pub mod unicode_font;
114pub mod watermark;
115
116pub use content_editor::{ContentEditor, GraphicsSnapshot, GraphicsStateTracker};
117pub use error::{ManipError, Result};
118pub use text_run::{FontMap, TextRun};