pdf/src/read/text.rs#
Source: lib/pdf/src/read/text.rs
The text of a page (ISO 32000-1, 9.4): the content stream is interpreted for its text
state (fonts, sizes, the text and line matrices, character and word spacing, horizontal
scaling, rise, the current transformation matrix with q / Q and cm, form XObjects with their
own matrix and resources), and every glyph shown becomes a TextItem with its text, origin and
advance in page space. PageText::text lays them out as Poppler's pdftotext -raw does: in the
order the page draws them, a new line where the baseline moves by more than half the font
size, a space where a gap is wider than 0.15 of it (0.08 after a space glyph; a space glyph
that leaves no gap is no space; a glyph without text leaves a gap), a glyph drawn again on
one of the last 64 (fake bold, a word printed twice) once, a run of Hebrew or Arabic drawn
left to right in reading order.
struct TextItemone glyph shown on a pagetext: String-- the characters the glyph stands for (usually one; empty when the font does not say)x: f64-- where the glyph starts on its baseline, in page space (points, y up, before /Rotate)y: f64dx: f64-- how far the glyph moves the pen, in page space (along the baseline; with character and word spacing)dy: f64width: f64-- the glyph's own width along the baseline in page space (without the spacing)size: f64-- the font size in page spacefont: u16-- which of PageText::fontsinvisible: bool-- render mode 3: drawn invisibly (the text layer of a scan)
struct PageTextthe glyphs of a page and the names of their fontsitems: Vec<TextItem>fonts: Vec<String>
impl Document
fn page_text(&self, page: usize) -> Result<PageText, Error>the glyphs of a page, in the order the page draws themfn text(&self, page: usize) -> Result<String, Error>the text of a page in reading order (PageText::text)
impl PageText
fn text(&self) -> Stringthe text: lines in the order the page draws them, words apart where the glyphs are, right-to-left runs in reading order