Rust API Reference¶
The stable Rust entry point is the open_redact_pdf crate.
Core types¶
PdfDocument¶
Primary document handle for parsing, inspection, redaction, and save.
Methods:
PdfDocument::open(bytes: &[u8]) -> PdfResult<PdfDocument>PdfDocument::page_count(&self) -> usizePdfDocument::page_size(&self, page_index: usize) -> PdfResult<PageSize>PdfDocument::extract_text(&self, page_index: usize) -> PdfResult<PageText>PdfDocument::search_text(&self, page_index: usize, query: &str) -> PdfResult<Vec<TextMatch>>PdfDocument::apply_redactions(&mut self, plan: RedactionPlan) -> PdfResult<ApplyReport>PdfDocument::save(&self) -> PdfResult<Vec<u8>>
PageSize¶
Coordinates are expressed in normalized page-space PDF units.
PageText¶
text is a human-readable page string assembled from extracted text runs. items carry geometry for future authoring workflows such as selection-driven redaction.
TextItem¶
Re-exported from pdf_text.
Important fields:
textbboxquadchar_startchar_end
TextMatch¶
Re-exported from pdf_text.
Important fields:
textpage_indexquads
Search results are returned as merged visual match regions rather than raw content-stream character order.
RedactionMode¶
Re-exported from pdf_targets.
pub enum RedactionMode {
Strip, // remove bytes; text shifts, no overlay
Redact, // blank space + colored overlay (default)
Erase, // blank space, no overlay
}
RedactionPlan¶
Re-exported from pdf_targets.
Important fields:
targetsmode— controls visual output (seeRedactionMode)fill_coloroverlay_textremove_intersecting_annotationsstrip_metadatastrip_attachments
RedactionTarget¶
Re-exported from pdf_targets.
Variants:
RectQuadQuadGroup
ApplyReport¶
Re-exported from pdf_redact.
Important counters:
pages_touchedtext_glyphs_removedpath_paints_removedimage_draws_removedannotations_removedwarnings
PdfError¶
Re-exported from pdf_objects.
Typical categories in the MVP:
- invalid page index
- parse or corruption errors
- unsupported PDF features
- unsupported options
Example¶
use open_redact_pdf::{PdfDocument, RedactionMode, RedactionPlan, RedactionTarget};
let mut document = PdfDocument::open(&bytes)?;
let matches = document.search_text(0, "account")?;
let targets = matches
.into_iter()
.map(|match_| RedactionTarget::QuadGroup {
page_index: match_.page_index,
quads: match_.quads.into_iter().map(|quad| quad.points).collect(),
})
.collect();
document.apply_redactions(RedactionPlan {
targets,
mode: Some(RedactionMode::Redact),
fill_color: None,
overlay_text: None,
remove_intersecting_annotations: Some(true),
strip_metadata: Some(true),
strip_attachments: Some(true),
})?;
let output = document.save()?;
# Ok::<(), Box<dyn std::error::Error>>(())