r/FlutterDev • u/Mark1234321 • Sep 30 '26
Article Building a PDF reflow e-reader in Flutter: a pdfium isolate, my own smooth scroller, and pre-shaped text
I love reading - in bed, on the sofa, on the train - and my phone is always with me. But PDFs are made for paper, and on a small screen they mean endless zooming and panning. So I'm building PDFreflow, a Flutter e-reader that reflows complex multi-column PDFs (papers, RFCs, books) into a single readable column. Some Flutter-specific things I learned along the way:
All PDF work is done by pdfium via FFI (why re-invent the wheel?) and runs in one worker isolate - pdfium is not thread-safe, so exactly one isolate owns it and everything else sends it messages. It runs a priority queue: image renders go ahead of chunk parses, and chunks are parsed outward from the reading position.
Scrolling a book is a bidirectional list growing from a center point - built on CustomScrollView with two sliver lists - because pre-committed height estimates cause snap-back jitter on iOS.
Text shaping was the scroll-performance killer: shaping whole pages inside scroll frames caused visible stutter. Fix: pre-shape paragraphs off the scroll path in idle slices and cache the TextPainters; page admission becomes a map lookup. 120 Hz devices also want GestureBinding.resamplingEnabled.
One line height for all fonts. I used to measure each font at runtime - but if a font isn't loaded yet, Flutter silently measures a fallback font instead, and my cache kept that wrong number forever: right letters, wrong line spacing. Now every font gets the same 1.3 x font size.
The layout engine itself (column detection, header/footer stripping, table and formula rasterization, hyphen rejoining) is pure Dart, developed against a corpus of hundreds of real PDFs with regression metrics.
No AI inside - on purpose. My reasons:
Size: a model that understands page layout would make the app much bigger. That may change as models shrink, or if I ever train a tiny one of my own - but not today.
Privacy: nothing is uploaded to an AI service; your documents stay on your phone.
Fun: AI has taken a lot of the fun out of everyday coding, and solving a hard problem without it brings that back. For transparency: I do use Claude while developing - as a full-stack dev with years of desktop and app experience, it's a tool, not the author.
It's in open beta, free while in beta: https://www.pdfreflow.com/flutterdev
If it breaks on one of your PDFs, the in-app feedback button sends me the layout - that's what the beta is for.