Skip to main content

Crate pdf_inspector

Crate pdf_inspector 

Source
Expand description

Smart PDF detection and text extraction using lopdf

§Quick start

// Full processing (detect + extract + markdown) with defaults
let result = pdf_inspector::process_pdf("document.pdf").unwrap();
println!("type: {:?}, pages: {}", result.pdf_type, result.page_count);
if let Some(md) = &result.markdown {
    println!("{md}");
}

// Fast metadata-only detection (no text extraction)
let info = pdf_inspector::detect_pdf("document.pdf").unwrap();
println!("type: {:?}, pages: {}", info.pdf_type, info.page_count);

// Custom options via builder
use pdf_inspector::{PdfOptions, ProcessMode};
let result = pdf_inspector::process_pdf_with_options(
    "document.pdf",
    PdfOptions::new().mode(ProcessMode::Analyze),
).unwrap();

Re-exports§

pub use detector::detect_pdf_type;
pub use detector::detect_pdf_type_mem;
pub use detector::detect_pdf_type_mem_with_config;
pub use detector::detect_pdf_type_with_config;
pub use detector::DetectionConfig;
pub use detector::PdfType;
pub use detector::PdfTypeResult;
pub use detector::ScanStrategy;
pub use extractor::extract_text;
pub use extractor::extract_text_with_positions;
pub use extractor::extract_text_with_positions_and_rotations_mem;
pub use extractor::extract_text_with_positions_and_rotations_mem_in_frame;
pub use extractor::extract_text_with_positions_and_rotations_mem_with_options;
pub use extractor::extract_text_with_positions_mem;
pub use extractor::extract_text_with_positions_mem_in_frame;
pub use extractor::extract_text_with_positions_mem_with_options;
pub use extractor::extract_text_with_positions_pages;
pub use extractor::extract_text_with_positions_pages_with_password;
pub use extractor::PositionFrame;
pub use extractor::PositionOptions;
pub use markdown::to_markdown;
pub use markdown::to_markdown_from_items;
pub use markdown::to_markdown_from_items_with_rects;
pub use markdown::to_markdown_from_items_with_rects_and_page_count;
pub use markdown::MarkdownOptions;
pub use markdown::MarkdownProfile;
pub use process_mode::ProcessMode;
pub use types::BoldSource;
pub use types::LayoutComplexity;
pub use types::PdfLine;
pub use types::PdfRect;
pub use types::TextItem;

Modules§

adobe_korea1
Adobe-Korea1 CID-to-Unicode mapping table.
detector
Smart PDF type detection without full document load
extractor
Text extraction from PDF using lopdf
glyph_names
Glyph name to Unicode mapping
markdown
Markdown conversion with structure detection.
process_mode
structure_tree
Tagged PDF structure tree parser.
tables
Table detection and formatting.
text_utils
Character classification and text utility functions.
tounicode
ToUnicode CMap parsing for PDF text extraction
types
Shared types used across the extraction and markdown pipelines.
vision
Optional native vision primitives used by OCR pipelines.

Structs§

FontCMapGaps
A font whose ToUnicode CMap (or, for a font without one, the embedded program’s own cmap table) had no entry for some of the codes the document shows through it, and what became of those codes.
PageMarkdown
Per-page markdown extraction result.
PageOcrReasons
OCR reasons for a single 1-indexed page.
PageRegionResult
Result for a page’s region extractions.
PagesExtractionResult
Combined per-page markdown extraction and layout classification result.
PdfClassification
Lightweight classification result for routing decisions.
PdfOptions
Configuration for process_pdf_with_options and friends.
PdfProcessResult
High-level PDF processing result.
RegionText
Result for a single region’s text extraction.
StructureElement
One structure-tree element reference from a tagged PDF, resolved to a page and Marked Content ID.
TableExtractionResult
Markdown for one extracted table plus a diagnostic flag describing which path produced it.
TsrTableInput
Input for extract_tables_with_structure_mem: one cropped table region plus the raw structure-recovery output for it.
VectorGridDetection
Region-scoped vector grid detection result for TSR-compatible callers.

Enums§

PageRotation
Which way a page’s coordinate frame was turned so that predominantly rotated text reads along +x.
PdfError

Constants§

OCR_REASON_INVISIBLE_TEXT_LAYER
OCR reason: every text-showing operator on the page leaves nothing to see — text render mode 3 (invisible), or mode 7 (clip only) with nothing painted through the clip — while an image covers at least half of the page: a scan carrying a text layer nobody sees. What that layer says is not what the page shows, so the page is read from its raster.
OCR_REASON_NO_TEXT
OCR reason: the page has no extractable text and no image to OCR — blank, or content the parser cannot reach.
OCR_REASON_SCANNED
OCR reason: the page is a scanned image (a full-page raster / image-only page) with no usable text layer.
OCR_REASON_SUSPECTED_GARBLED_TEXT
OCR reason emitted when the extracted text layer appears garbled due to broken font decoding or mojibake.
OCR_REASON_VECTOR_TEXT
OCR reason: the page’s text is drawn as vector outlines (path operators) rather than real text operators, so it cannot be extracted as characters.

Functions§

classify_pdf_mem
Classify a PDF from a memory buffer without extracting text. Returns the PDF type and which pages need OCR (~10-50ms).
collect_text_in_region
Collect text items that fall within a region bbox (top-left origin, PDF points) and return them as a single string in reading order.
collect_text_in_region_in_frame
collect_text_in_region with the page’s coordinate frame given explicitly instead of inferred: rotation is the turn extract_text_with_positions_and_rotations_mem reported for the items’ page (PageRotation::Upright for pages absent from that map). The region bbox stays in top-left page coordinates and is turned to match.
detect_pdf
Fast metadata-only detection — no text extraction or markdown generation.
detect_pdf_mem
Fast metadata-only detection from a memory buffer.
detect_vector_grid_in_region_mem
Detect a vector ruled-line / rectangle grid inside one page region.
extract_pages_markdown
Path-based wrapper for extract_pages_markdown_mem.
extract_pages_markdown_mem
Extract formatted markdown for pages of a PDF, with layout classification metadata.
extract_structure_elements
Path-based wrapper for extract_structure_elements_mem.
extract_structure_elements_mem
Extract structure-tree element references from a tagged PDF in memory.
extract_tables_in_regions_mem
Extract tables within bounding-box regions from a PDF in memory.
extract_tables_in_regions_mem_in_frame
extract_tables_in_regions_mem with the frame of the region rects given explicitly — see extract_text_in_regions_mem_in_frame.
extract_tables_in_regions_mem_with_options
extract_tables_in_regions_mem_in_frame with every option given as a PositionOptions — see extract_text_in_regions_mem_with_options.
extract_tables_with_structure_auto_mem
Auto-fallback variant of extract_tables_with_structure_mem: runs the TSR-hybrid path, checks the resulting cells for known SLANet detection pathologies (phantom rows, multi-row-in-cell text), and falls back to the heuristic extract_tables_in_regions_mem for any input where the TSR path looks compromised.
extract_tables_with_structure_cells_mem
Extract structured cells using externally-supplied structure recovery.
extract_tables_with_structure_mem
Extract markdown tables using externally-supplied structure recovery.
extract_text_in_regions_mem
Extract text within bounding-box regions from a PDF in memory.
extract_text_in_regions_mem_in_frame
extract_text_in_regions_mem with the frame of the region rects given explicitly. PositionFrame::Sheet reads them as that function does; PositionFrame::Display reads them on the rendered page — the visible page box turned clockwise by the page’s inheritable /Rotate, top-left origin, y down — the frame a layout model working on a page image reports boxes in. Pages whose text is predominantly rotated are handled the same way in both frames.
extract_text_in_regions_mem_with_options
extract_text_in_regions_mem_in_frame with every option given as a PositionOptions: the frame the region rects are read in, and whether bold is also read from the font’s weight class (bold_from_weight: a weight class of bold_weight_threshold or more, 600 by default, is bold, and a run the weight makes bold is then its own item while the region’s lines are assembled). The default options are extract_text_in_regions_mem.
process_pdf
Process a PDF file with full extraction (detect → extract → markdown).
process_pdf_mem
Process a PDF from a memory buffer with full extraction.
process_pdf_mem_with_configDeprecated
Process PDF from memory buffer with custom detection and markdown configuration.
process_pdf_mem_with_options
Process a PDF from a memory buffer with custom options.
process_pdf_with_configDeprecated
Process a PDF file with custom detection and markdown configuration.
process_pdf_with_config_pagesDeprecated
Process a PDF file with custom configuration and optional page filter.
process_pdf_with_options
Process a PDF file with custom options.
widen_degenerate_form_bboxes_mem
The PDF written back out with the /BBox of its Form XObjects repaired — a zero-area box widened, numerals too large for any parser saturated — for callers that render the document with their own renderer. Rust only: the Python, Node.js and WebAssembly bindings do not expose it.