MJ PDF
Open source

How a PDF Reader Works: PDFium, Rendering and Text Extraction Explained

A PDF is not an image. It is a structured description of pages, fonts, text and shapes. Turning that description into pixels on your phone is the job of a rendering engine. Knowing the layers helps explain why some PDFs are fast, some are slow and some will not reflow.

MJ PDF website2 min read5 sections

Layer one: the engine

The project’s page names PDFium, an open-source engine from Google, as the layer that actually converts PDF pages into images. It parses the file, resolves fonts and draws every page at the resolution requested.

Layer two: the Android bridge

A native engine written in C++ needs a bridge to be called from Android code. The project credits two open-source libraries by barteksc for this role: one exposes PDFium to Java and Kotlin, and another displays pages and handles scrolling and zooming. Since 3.0.0, MJ PDF maintains its own forks of both.

Layer three: the reader

On top sit the features you see: library, search, annotations, themes and Text Mode. According to the project, its own forks are used to customise reader behaviour, improve rendering performance, support text selection and extraction, detect crop margins, handle forms, create and edit annotations and save signatures into PDFs.

Why text extraction can fail

Selecting, searching and reflowing all rely on text data in the file. If a page is a scanned image, there is no text to extract. Some files also encode text oddly, so copied words may come out garbled. This is a property of the file as much as the reader. See fixed layout vs reflow.

Why maintaining your own build matters

The project says it maintains its own PDFium build pipeline so that native libraries can be updated, patched and optimised, rather than depending on old prebuilt binaries. For a reader that handles files from many sources, staying current on the rendering engine is a security and compatibility matter, not just a performance one.

Key points

  • PDFium renders pages; a bridge layer connects it to Android; the app adds features.
  • Selection, search and reflow all depend on a text layer in the file.
  • Maintaining the build pipeline lets a project update and patch native code.

Questions

Is PDFium the same engine used in Chrome?

PDFium is Google’s open-source PDF engine, and it is the one the Chromium project uses for PDFs too. MJ PDF uses its own build of it.

Get MJ PDF 3.1.0

Free, open source and ad-free. Install it from F-Droid or IzzyOnDroid, or read the source on GitLab.