[feat-008] pdf-4up rendering via pdftoppm - fixes blank-image bug + 3× compression

↗ view on GitHub · Nick Whitehouse · 2026-05-06 · 787258cb

Two outcomes in one commit:

1) Fixes a silent vision-mode bug. The prior pdfjs+node-canvas glyph
   rendering produced blank PNGs - canvas v3 dropped Path2D, pdfjs 4.x
   needs it for glyph paths, and the path2d polyfill didn't bridge the
   gap. Vision-mode answers were entirely from read_document text
   fallback; vision input was noise. Rendering now shells out to
   pdftoppm (poppler-utils), which is battle-tested and renders glyphs
   correctly.

2) Switches to 4-up grid composition (default pagesPerImage=4). Two
   independent spike rounds (25-page services agreement and 75-page
   SEK financing doc, see backend/spike-out/text-compression*) showed
   ≈3× token compression vs 1-up at no fidelity loss on legal-grade
   factual queries (dates, currency amounts, party names, repayment
   terms). 8-up was rejected - round 1 hallucinated, round 3 returned
   mostly empty.

Combined effect: 4× page capacity per request (100 images × 4 pages =
≈400 PDF pages), blank-image bug gone, ~3× cheaper. The 75-page SEK
test doc that previously truncated to 30 pages in 1-up now fits whole.

Files:
- nixpacks.toml: aptPkgs += poppler-utils
- src/lib/pdfRender.ts: rewritten - pdftoppm + grid composer
- src/lib/visionContext.ts: VISION_MAX_IMAGES_PER_REQUEST=100, pass
  pagesPerImage:4 to renderer

read_document text-fallback stays in place as a safety net.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Repository nwhitehouse/mike
Author Nick Whitehouse <nick.whitehouse@mccarthyfinch.com>
Authored
Parents 436d028d
Stats 3 files changed , +223 , -133
Part of Vision mode: PDF page images → Olava (feat-007a / 008 / 009 / 010 / bug-005)

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-787258cb.md from inside the repo you want the change in.

⬇ Download capture-commit-787258cb.md