Expand description
§pdfrum-text
Text extraction (ISO 32000-1 §14.8.2): reading order, search, selection geometry, word segmentation and bare-URL detection. It walks the same interpreted page-object graph the renderer walks and never rasterizes, so extracting text from a page costs no pixels and needs no backend.
use pdfrum_text::{FindOptions, TextIndex, TextPage};
let page = TextPage {
search_text: "Hello, world!".chars().collect(),
..TextPage::default()
};
let hit = page.find("world", FindOptions::default()).next().expect("a match");
assert_eq!(hit, TextIndex::new(7)..TextIndex::new(12));Two index spaces, and mixing them is the bug this crate is shaped to
prevent. CharIndex addresses what the page draws — every glyph in
drawing order, including generated spaces, hyphens at line breaks and control
characters that have geometry but no meaning. TextIndex addresses what
search and copy see, with those removed. A hit from TextPage::find is a
TextIndex range; TextPage::rects and TextPage::char want a
CharIndex; IndexMap is the conversion, and the two are distinct types so
the compiler refuses the mistake rather than returning a highlight in the
wrong place.
Geometry is per character, not per line. CharBox carries each glyph’s
quadrilateral in page space, which is what makes TextPage::rects able to
return a selection that follows rotated or skewed text,
TextPage::index_at able to answer a click, and TextPage::text_in_rect
able to lift a column out of a two-column page.
Reading order is reconstructed, not read off the file: a content stream may
draw a page’s text in any order at all, and extract sorts runs into the
order a human reads them, right-to-left when
ExtractOptions::rtl says so.
Part of pdfrum. #![forbid(unsafe_code)].
MIT OR Apache-2.0
Structs§
- CharBox
- One extracted character, with its metrics and page geometry.
- Char
Index - A position in the character list (
TextPage::chars) — the sequence a--txtdump emits. - Char
Segment - One run of characters that made it into the text.
- Extract
Options - How extraction behaves.
- Find
Options - How a search behaves.
- Index
Map - The map between the two index spaces of
TextPage. - Object
Index - A text object’s position in the page’s flattened object walk.
- Text
Index - A position in the search-facing text (
TextPage::search_text) — what a search matches and a selection copies. - Text
Page - One page’s extracted text (ISO 32000-1 §14.8.2).
- TextRun
- A text object with everything the heuristics ask of it.
- WebLink
- One address found in a page’s text.
- Word
- One word of a page’s text, from
TextPage::words.
Enums§
- Char
Type - Where a character came from, which decides how the rest of the pipeline treats it.
- Error
- What can go wrong querying an extracted page.
- Orientation
- Which way a line of text runs.