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§
- Document
Info - 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_fromcan actually address.