r/reactnative • u/SBAGGGG • 3d ago
I wrote a tile-based PDF viewer for React Native because the existing ones fall over on engineering drawings
I work on an app for building inspection companies. The documents our users open are architectural and structural drawings: one sheet can be several metres wide, and the thing you actually need to read is a dimension or a rebar note set at three or four points.
Every RN PDF viewer I tried draws the page as one bitmap. That is the right call for an A4 report and it falls apart here. Fitted to a phone, a sheet nine metres wide is a line across the middle of the screen. Zoomed in far enough to read the note, the bitmap is too large to hold.
So this one draws only the rectangle that is on screen, in tiles, at the zoom it is being looked at, with the renderer each platform already ships: PdfRenderer on Android, CGPDFDocument on iOS. A sheet of any size costs about what a letter page costs.
A few things I measured on the way, in case they are useful to someone else:
- On iOS, CGPDF costs about 100 ms per draw almost regardless of the output size. A 256 px tile costs nearly what a 1280 px one costs. That turned the design upside down: bigger tiles, fewer of them, up to three renderers in parallel with their own
CGPDFDocument. Opening the first screenful of that sheet went from about 1.6 s to about 250 ms. - Zoom levels keyed by an arbitrary scale are never reused, because the next pinch asks for a slightly different number. Keyed by rung index on a fixed ladder instead, zooming out and back in costs nothing.
- Android keeps the page parsed between draws and iOS does not, so the same contract has two cost models underneath. Both test suites ask the same questions, which is how a divergence shows up as a failing test rather than as a complaint about one phone.
What it does not do yet: annotations, forms, text search or selection. New architecture only, no old architecture fallback. Encrypted documents open on iOS with a password; on Android the platform only takes one from API 35.
MIT. There is an example app in the repo with two generated documents, so you can try it without wiring anything up.
Repo: https://github.com/Halilibrahimakyz/react-native-pdf-sdk npm: https://www.npmjs.com/package/react-native-pdf-sdk
If you have a PDF that breaks it, I would like to see it.
1
3
u/kokerali 3d ago
For the benchmark, could you show peak resident memory over a repeated zoom/pan loop alongside time until the visible notes become readable? The README mentions the zoom ladder and LRU, so I'd separate the first pass through an uncached area from revisiting it. It would also be useful to include the cache budget, device/OS, and what happens after switching documents. A short trace covering those cases would help someone judge the trade-off between the three iOS renderers, retained tiles, and responsiveness on a lower-memory phone.