Convert PDF to Markdown in pure Rust

Weavon extracts born-digital and multi-column PDFs into clean Markdown, JSON, or RAG chunks using a structure tree and XY-cut layout engine with an optional OCR hook.

Structure trees first, XY-cut columns second

  • Tagged PDF tree

    Reads /StructTreeRoot headings, lists, paragraphs, and tables directly when present.

  • Multi-column XY-cut

    Splits multi-column academic and report layouts into natural reading order on untagged PDFs.

  • Direct RAG chunks

    weavon extract --format chunks

    Emits JSON Lines records with heading_path and token estimates in one pass.

  • Optional OCR hook

    --ocr CMD

    Pipes scanned image pages to your local OCR command with page metadata env vars.

Extract PDFs, Office docs, and URLs with one verb

weavon extract paper.pdf --format markdown -o paper.md
weavon extract paper.pdf --format chunks --max-tokens 512 -o paper.jsonl
weavon extract scan.pdf --ocr "tesseract stdin stdout" -o scan.md

The same weavon extract command reads PDF, DOCX, PPTX, HTML, EPUB, LaTeX, and remote URLs when you pass --allow-network.

Known limits for PDF extraction

  • Weavon does not bundle an embedded OCR neural model inside the 9.26 MB binary. Scanned image pages emit W_PDF_SCANNED_PAGE_NEEDS_OCR unless you pass --ocr CMD.
  • Complex rotated tables and handwritten annotations may need a dedicated vision pipeline.

Extract Markdown from a PDF

  1. Extract clean Markdown

    Run weavon extract on a born-digital PDF to get heading-structured Markdown.

    weavon extract report.pdf --format markdown -o report.md
  2. Emit RAG JSON Lines

    Switch --format to chunks for token-bounded retrieval records.

    weavon extract report.pdf --format chunks --max-tokens 512 -o chunks.jsonl
  3. Add an OCR command for scans

    Pass --ocr CMD when processing image-only scanned PDF pages.

    weavon extract scanned.pdf --ocr "tesseract stdin stdout" -o scanned.md

Common questions

How does Weavon handle multi-column PDFs?

When a PDF is tagged, Weavon reads the logical structure tree. For untagged PDFs, v0.2.0 applies an XY-cut layout pass to reconstruct multi-column reading order.

Does Weavon do OCR on scanned PDFs?

Weavon does not bundle an OCR model in the 9.26 MB binary. Pass --ocr CMD to weavon extract to run Tesseract or another local recognizer on scanned pages.

Can I convert PDFs to Markdown in the browser?

Yes. The weavon-wasm build with --features pdf reads born-digital PDFs locally in the playground with no file upload.

What output formats does weavon extract support?

weavon extract writes markdown, json (Pandoc AST), or chunks (JSON Lines for RAG).