Skip to main content

Module words

Module words 

Source
Expand description

Word-level boxes for citations, highlighting and grounding.

PdfDocument::extract_words is the extract_words=True of pymupdf4llm: every word of the document with the box it was drawn in. It is built from the blocks PdfDocument::extract_blocks returns – same options, same window – splitting each span’s text on whitespace and boxing each word from the glyphs that drew it. One function, no second text pass.

A word’s box is the union of its glyphs’ boxes turned into the page frame: an upright word’s boxes pass through untouched, a turned word’s become the axis-aligned envelope of its turned glyphs. Boxes are one per glyph while characters count the spaces the text pass inserted too, so each span first aligns its two: a space sitting in a gap between glyphs owns no box, a drawn one owns its glyph’s, and a glyph one character stands for keeps its whole box however many letters it decodes to. A word the page split across spans joins by the rule text joins by (crate::words_join::pieces_join), so joining a line’s words with single spaces is the line’s own text.

Structs§

Word
One word of a document’s text, with the box it was drawn in.

Functions§

to_json_with_words
The blocks as JSON, each block carrying the lines it groups.
to_words_json_lines
The words as JSON lines, one object per word.