pub struct ExtractionOptions {Show 13 fields
pub preserve_layout: bool,
pub space_threshold: f64,
pub tj_space_threshold: f64,
pub newline_threshold: f64,
pub sort_by_position: bool,
pub detect_columns: bool,
pub column_threshold: f64,
pub merge_hyphenated: bool,
pub track_space_decisions: bool,
pub reconstruct_paragraphs: bool,
pub include_artifacts: bool,
pub reorder_columns: bool,
pub max_extracted_bytes: Option<usize>,
}Expand description
Text extraction options
Fields§
§preserve_layout: boolPreserve the original layout (spacing and positioning)
space_threshold: f64Minimum space width to insert space character (in text space units)
tj_space_threshold: f64Threshold for synthesising an implicit U+0020 from a TJ numeric
kerning offset, expressed as a fraction of the current font size.
A TJ kern advances the text matrix by -adjustment/1000 * font_size
without rendering any glyph; many PDFs (academic publishers, LaTeX,
kerned typography) encode inter-word gaps purely as wide negative
kerns rather than literal space bytes. When the synthesised advance
exceeds tj_space_threshold * font_size, the extractor inserts one
U+0020. Default 0.2 (200 milli-em) sits well between typical
intra-word kerning (10-50 milli-em) and the width of a space
glyph in most fonts (250-300 milli-em). Lower values catch tighter
spaces; higher values reduce false positives in fonts with unusually
wide kerning. Separate from space_threshold (which governs the
post-glyph gap between separate text-show operators) because the TJ
numeric kern is measured without any glyph advance baseline and
needs a more sensitive threshold (issue #272).
newline_threshold: f64Minimum vertical distance to insert newline (in text space units)
sort_by_position: boolSort text fragments by position (useful for multi-column layouts)
detect_columns: boolDetect and handle columns
column_threshold: f64Column separation threshold (in page units)
merge_hyphenated: boolMerge hyphenated words at line ends
track_space_decisions: boolTrack space insertion decisions in each TextFragment (default: false).
When false: zero overhead. When true: populates TextFragment::space_decisions.
reconstruct_paragraphs: boolReconstruct visual lines and paragraphs from the raw text fragments
produced by PDF text-show operators. When true, the extractor groups
fragments by baseline into single-line fragments, then groups
consecutive lines with normal leading into paragraph-level fragments.
This is what the partition pipeline needs to produce Element values at
paragraph granularity rather than at per-Tj granularity (see
issue #261).
Default false for backward compatibility with direct extract_text
callers. The PdfDocument::partition* entry points force this to
true.
include_artifacts: boolInclude content inside /Artifact marked-content scopes (page headers,
footers, watermarks, decorative content). Default false — Artifact
content is filtered out, as the PDF/UA conformance level recommends
for accessibility tooling and as RAG callers consistently want
(issue #269 Phase 1). Opt-in by setting true when extracting
page furniture matters (e.g. forensic auditing, redaction tools).
reorder_columns: boolReorder flat-text output by column so per-column tokens stay adjacent in
multi-column layouts (issue #389). Only affects the flat path
(preserve_layout = false); in layout mode detect_columns already
reorders. Default false → the flat path is byte-identical to before.
When on, .text is produced by the fragment pipeline (its shape matches
the layout path’s reconstruction, not stream order); .fragments stays
empty.
Column reflow only triggers for column blocks whose rows are spaced at least one line height apart. Layouts pitched tighter than that are geometrically indistinguishable from tight-leading prose that merely contains a wide gap, so they are intentionally left in reading order rather than risk shredding prose (issue #417); text is never corrupted.
Column blocks require gaps that align horizontally across rows: a set of unrelated wide gaps at different X (e.g. a label/value form with varying label lengths) is left in reading order, never reflowed (#422). A genuine table whose column corridor drifts more than ~10pt between rows may also be left un-reordered; text is never corrupted.
max_extracted_bytes: Option<usize>Stop accumulating decoded text for a page once this many bytes have been
collected, bounding the per-page peak memory of extraction. The limit is
enforced during accumulation, not by truncating the finished string, so
a single page with a huge or adversarially inflated content stream cannot
materialise an unbounded String before the caller sees it (issue #382).
Semantics are undershoot: extraction stops before the fragment that
would push the accumulated bytes past the limit, so the returned
text.len() <= max_extracted_bytes and a multi-byte UTF-8 character is
never split. When the limit cuts extraction short,
ExtractedText::truncated is set to true.
None (default) means no limit — output is byte-identical to before.
The text.len() <= max_extracted_bytes invariant holds on every path
(flat, reorder_columns, preserve_layout): the layout paths rebuild
.text from the already-bounded fragment set and are then clamped to the
limit at a UTF-8 char boundary as a final safety net.
Because whole decoded runs are the unit of truncation, a page whose text
is a single run larger than the whole budget (e.g. one huge Tj, or an
/ActualText override) comes back with text == "" and
truncated == true rather than a partial run — the limit is never
satisfied by splitting a run mid-character.
Trait Implementations§
Source§impl Clone for ExtractionOptions
impl Clone for ExtractionOptions
Source§fn clone(&self) -> ExtractionOptions
fn clone(&self) -> ExtractionOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more