Skip to main content

Module documents

Module documents 

Source
Expand description

Reading paged documents — PDFs today.

A document can be read two ways, and which is right depends on the document rather than on preference:

  • Extract its text layer. Cheap, exact, and works with any text model. Useless for a scanned page, which has no text layer at all.
  • Render pages to images for a vision model. Works on anything a human could read, including scans, and preserves layout, tables, and figures that extraction flattens or drops. Far slower and needs a vision model.

So the host reports what a document offers — page count, and whether a text layer exists — and the block decides. That is why MediaKind::Document carries has_text_layer: a block that checks it can take the cheap path when it exists and the expensive one when it must, instead of silently extracting nothing from a scan and summarizing the empty string.

§Why rendering is optional

Text extraction is pure Rust and always available. Rasterizing needs a PDF renderer, which is a large native dependency, so it sits behind the pdf-render feature. Without it, render_page fails with a message saying exactly that rather than pretending the page is blank.

Structs§

DocumentInfo
What a document offers a block.

Functions§

document_text
Every character of text in the document, in one call.
inspect
Inspect a PDF without committing to reading all of it.
page_count
How many pages the PDF’s own page tree reports.
page_text_from
Take one segment of already-extracted text, zero-based.
render_page
Render one page to a PNG, zero-based.
text_segments
How many text segments page_text_from can actually address.