Expand description
Async I/O wrappers via Tokio’s blocking pool. Layout-aware text replacement engine (find & replace by match id). Layout-aware text editing: find → stage → commit (Phase 1B engine).
This is the match-based replacement engine designed in
docs/TEXT_REPLACE_ENGINE_DESIGN.md. Unlike crate::text_replace it
never skips silently, preserves the page’s /Contents stream structure,
detects text in Form XObjects, refuses signed documents by default and
reports every staged edit.
use lopdf::Document;
use pdf_manip::text_edit::{begin_text_edit, DocumentRevision, ReplaceOptions, TextQuery};
let bytes = std::fs::read("in.pdf").unwrap();
let mut doc = Document::load_mem(&bytes).unwrap();
let revision = DocumentRevision::from_source_bytes(&bytes);
let mut session = begin_text_edit(&mut doc, revision).unwrap();
let matches = session.find_text(TextQuery::exact("Acme B.V.")).unwrap();
session
.stage_replace(&matches[0].id, "Example B.V.", ReplaceOptions::default())
.unwrap();
let report = session.commit().unwrap();
assert_eq!(report.replacements_applied, 1);Structs§
- Commit
Error - A failed commit: the first fatal cause plus the validation outcome of every staged edit. The document was not modified.
- Container
Info - Container identity of a match or a modified stream.
- Diagnostic
- A coded, human-readable observation attached to matches and results.
- Document
Revision - Identifies one exact revision of a document during text editing.
- MatchId
- Opaque, serializable locator for one text match.
- Match
Span - One text-showing operator touched by a match.
- Match
Style - Visual style at the start of a match.
- Replace
Options - Options for one staged replacement.
- Signature
Summary - A digital signature found in the document.
- Text
Edit Session - An in-progress text-edit transaction (design §2).
- Text
Match - One found occurrence.
- Text
Query - A text search query. Matching operates on the decoded visual text of the logical reading sequence per container (design §10 / Phase 1B narrowing).
- Text
Replacement Report - Exhaustive commit report:
matches_found == replacements_applied + replacements_failedalways holds (no silent skips). - Text
Replacement Result - Per-edit result (design §4.4).
Enums§
- Commit
Policy - Transaction policy (design §10.4). Strictest-wins across the staged
edits: the commit runs
BestEffortonly when every staged edit requested it. - Container
Kind - Where a match lives.
- FitPolicy
- What the engine may do when replacement text does not fit (design §4.3).
Phase 1B implements only
FitPolicy::Exact. - Font
Fallback - Font fallback policy. Fallback use is never silent: it is always visible
in the per-edit result (
font_substituted). - Region
Relation - How a region rectangle selects matches (design §10.3).
- Replacement
Status - Outcome of one staged edit.
- Signature
Policy - Digital-signature policy (design §6).
- Stale
Reason - Why a
MatchIdno longer resolves (design §3). No fuzzy relocation is ever attempted. - Tagged
Text Policy - Tagged-text policy (design §7). Phase 1: reject
/ActualTextconflicts. - Text
Edit Error - Typed errors of the text-edit engine.
- Unsupported
Container - Container kinds the Phase 1B engine detects but cannot edit.
- Unsupported
Reason - Why a found match cannot be edited in this phase.
- Writing
Direction - Writing direction of matched text. Phase 1 supports LTR only.
Functions§
- begin_
text_ edit - Start a text-edit session on a document.
- replace_
text - Convenience: find + stage + commit in one call (design §4).