JFLib

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 TextItem one glyph shown on a page

    • text: 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: f64
    • dx: f64 -- how far the glyph moves the pen, in page space (along the baseline; with character and word spacing)
    • dy: f64
    • width: f64 -- the glyph's own width along the baseline in page space (without the spacing)
    • size: f64 -- the font size in page space
    • font: u16 -- which of PageText::fonts
    • invisible: bool -- render mode 3: drawn invisibly (the text layer of a scan)
  • struct PageText the glyphs of a page and the names of their fonts

    • items: 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 them
  • fn text(&self, page: usize) -> Result<String, Error> the text of a page in reading order (PageText::text)

impl PageText

  • fn text(&self) -> String the text: lines in the order the page draws them, words apart where the glyphs are, right-to-left runs in reading order

Source: docs/API.md in the JFLib repository.