/structured-data-skills:extract-document-textfrom structured-data-skills
Extract text from PDFs, office documents and images, including scanned PDFs that need OCR. Use when a PDF returns no text, when reading a specification or datasheet programmatically, or when a document must be searched, quoted or checked rather than only viewed.
Ships in structured-data-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Get text out of documents so it can be searched, quoted and verified — not merely displayed.
pdftotext returned nothing, or returned layout garbagexberg (renamed from kreuzberg, same author) handles ~100 formats and
falls through to OCR automatically when a PDF has no text layer. Prefer it as the default:
pdftotext. Only the OCR path costs seconds.pdftotext remains worth knowing as the zero-dependency fallback: it is everywhere, needs no
Python, and is correct whenever a text layer exists.
If you use it, check the word count and never the exit status. On a scanned PDF it exits 0 and produces an empty file — which reads as "empty document" rather than "wrong tool".
words=$(pdftotext doc.pdf - | wc -w)
[ "$words" -gt 0 ] || echo "no text layer — this needs OCR"
How far this was measured: two documents — one text-layer, one scan. Enough to prefer a default; not enough to claim it generally. Re-measure on your own corpus if the choice matters.
xberg ships as a Python package and as xberg-cli, a Rust binary — one project, one
version line (both 1.0.14 as of 2026-08-20), two entirely different calling conventions. Neither is
the real one. Pick by where you are calling from, and know which you installed: every note below is
specific to one of them.
| Python package | xberg-cli | |
|---|---|---|
| Get it | uv tool install xberg, pip install xberg | prebuilt binary from docs.xberg.io; also published on crates.io |
| Interface | async Python API | subcommands, text or JSON on stdout |
| Reach for it | you are already inside Python | a shell pipeline, a hook, a check, an agent |
The prebuilt binary is self-contained: it ships libheif, libaom, libx265 and libvmaf
alongside it, so HEIC and AV1 inputs work with no system codecs — and it is ~90 MB for that reason.
xberg extract document.pdf # plain text on stdout
xberg extract document.pdf --format json # structured
xberg extract --url https://…/spec.pdf # fetch and extract
xberg extract --stdin -m application/pdf # bytes on a pipe — the -m is not optional, see below
xberg detect document.pdf # MIME type only
xberg formats # 119 extension -> MIME rows
--stdinwithout-memits the raw file bytes and exits 0. Piping a PDF in with no MIME hint returns the file itself —%PDF-1.3, a binary run,3 0 obj,/Filter /FlateDecode,stream— the container rather than the document, reported as a success. Detection works from a path and not from a pipe, so on the--stdinpath the hint is load-bearing. Same shape aspdftotextexiting 0 on a scan: the failure arrives as content, not as an error.
--format json returns {"result": {…}, "extraction_time_ms": N}, so the text is at
.result.content — and the fields you need in order to trust it sit right beside it:
xberg extract doc.pdf --format json | jq -r '.result.extraction_method, .result.quality_score'
xberg extract doc.pdf --format json | jq -r '.result.content' > doc.txt
result carries content, mime_type, metadata, extraction_method, tables, counts and
quality_score.
OCR is flags, not a separate mode — and the flag worth knowing is not --ocr:
--ocr true|false, with --ocr-backend tesseract|paddle-ocr|vlm|candle-*--force-ocr true — OCR even where text extraction succeeded--ocr-scanned-pages — OCR only the pages that look like scans, keeping native text
elsewhere. The one to reach for on a mixed document, and it catches the nastiest case: a scanned
page carrying a junk hidden text layer that would otherwise pass the quality check and return
garbage as if it were native text--scanned-min-confidence defaults to 0.7. Its help records that 0.50 or lower also OCRs
born-digital slides using a full-bleed background image — a false positive you opt into, not one
you discoverbatch, chunk, embed and cache exist too, and serve/mcp expose extraction as an HTTP
or MCP server — a third integration route, and the one to consider before writing a wrapper.
Measured — macOS,
xberg-cli1.0.14, 2026-08-20, one text-layer PDF:xberg extractandpdftotextreturned the same 101 words, in 0.034 s and 0.039 s wall clock; self-reportedextraction_time_mswas 11.8. That is enough to say the native path costs nothing next topdftotext. It says nothing about the OCR path, and nothing about a corpus.
from xberg import ExtractInput, extract
output = await extract(ExtractInput(kind="uri", uri="document.pdf"))
print(output.results[0].content)
Three things about that call, each of which costs an hour if guessed:
await it, or you measure a coroutine object and conclude the tool is brokenExtractInput, not a path string; kind="uri" accepts a local pathoutput.results[0].content — the return value is a container; output.single is a
method, so output.single is not None is always true and tells you nothingAlways check extraction_method — output.results[0].extraction_method in Python,
.result.extraction_method in the CLI's JSON. It reports native for a text layer and ocr when
the page was recognised, and that distinction changes how far you can trust the text.
Structure recovery is document-dependent, not automatic. OCR performs layout analysis and can emit Markdown tables; the native path passes through whatever the PDF already contains. Measured: a scan produced Markdown tables, a text-layer policy document produced none. Do not assume you will get structure back.
OCR needs an engine installed — Tesseract is the common default. Expect seconds per document on that path only.
OCR text is not quotable without verification. Recognition silently substitutes characters, and a wrong character inside quotation marks is worse than no quote at all — it is citable and looks authoritative. Before quoting any passage where
extraction_method == "ocr", check it against the rendered page.
The three notes above are all stated on the project's own quickstart page. They were instead
rediscovered by dir()-ing Rust-backed objects across four failed attempts, each producing a
plausible "0 characters" that looked like a broken tool and was a broken measurement.
Before writing a line against an unfamiliar library: find its quickstart, and check whether it ships an assistant plugin or conventions file. Many now do, and that is the cheapest possible source of the calling convention.
When the document is behind a URL, the cost of getting this wrong is a plausible non-document — see the next section. Escalate deliberately; each rung is heavier and less reproducible than the one above it.
llms.txt, llms-full.txt, a single-page
print.html, the .md beside an HTML page — or, for a document with a canonical format, that
format: an RFC's .xml, a standard's source rather than its rendering. Cheapest, most faithful,
and it beats every rung below when it exists. See process-structured-data, A rendered document
is not the document. llms.txt is a proposal — Answer.AI, September 2024 — and
not a standard: no standards body has adopted it, whatever a search result tells you. Adoption
across tool and framework docs is still wide enough to be worth one request first.curl. The default whenever the target is already a document — a PDF, a spec, a raw file.
Milliseconds, no dependencies, byte-exact.xberg extract --url when you want the text rather than the bytes: it fetches and extracts
in one step, and reports extraction_method for what it did.Escalate on evidence, not on annoyance. A 200 carrying a challenge page, an SPA shell or a
cookie wall is the signal to go up a rung. A 200 carrying the document in a layout you dislike is
not — that is an extraction problem, and rung 4 will not fix it.
Rung 4 produces a different kind of evidence. A browser renders; what you captured is what that browser build produced on that date, and a later run may differ. When a claim rests on rendered behaviour rather than on a file's bytes, record the browser and its version beside the date. "Observed via Playwright, browser version not recorded" is a limit you will have to state in the record later; recording it costs one line now.
An extraction that returns something is not an extraction that returned the document.
200 or an exit 0 proves the tool ran. Grep the
output for text you know is in the document — a heading, a section number, a phrase.200 for any path, including ones that do not exist — so "blocked" and "the URL
is wrong" are indistinguishable. Confirm a URL from a page that actually resolves before recording
a source as unreachable.process-structured-data — once text is out, querying and editing it without corrupting the fileWhat SKILL.md sets; muted values are Claude Code's defaults
structured-data-skills@jrjsmrtn-skills is listed by jrjsmrtn/jrjsmrtn-skills — review the source before installing
npx claudepluginhub jrjsmrtn/jrjsmrtn-skills --plugin structured-data-skills2 skills in this plugin
Other plugins' skills for the same job