pdfium provides idiomatic R bindings to Google’s PDFium engine — the same library that powers Chrome’s PDF viewer. It has two halves:
- a read surface that exposes vector-path geometry — stroke / fill / Bezier control points / transformation matrices — alongside text, fonts, images, annotations, form fields, attachments, signatures, structure tree, and rendering. The path geometry, in particular, no CRAN package surfaces today.
- a mutation surface (opt-in via
readwrite = TRUE) that lets you rotate / reorder / merge pages, draw fresh page objects, create and edit annotations, fill form fields, and add file attachments — then save the result.
What it is for
- Auditing PDF figures (which lines, which colors, which fonts).
- Extracting curves from regulatory filings and scientific publications.
- Building PDF normalization pipelines that need geometry, not just text.
- Filling AcroForm fields programmatically and flattening the result for downstream tooling.
-
Authoring programmatic PDFs from vector graphics, JPEG images, text in the 14 standard fonts or any TrueType / Type1 typeface, and annotations (think: figure callouts, table reports, annotated source documents).
/Info-dict writes and on-save encryption are the remaining v0.1.0 gaps — both need upstream PDFium changes that we’ve proposed but Google hasn’t shipped yet. - Anything you’d otherwise drop into Python with
pypdfium2.
See vignette("mutating-pdfs") for a walkthrough of the writer surface, and vignette("comparison") for how pdfium lines up against pdftools, qpdf, magick, tabulizer, and staplr.
Status
Version 0.1.0. pdfium is not on CRAN and no CRAN release is planned, but it is held to CRAN’s quality bar: R CMD check --as-cran stays clean. The public API is documented on the pkgdown site and exercised at 100% R coverage; architectural decisions are recorded under dev/decisions/.
Installation
# From r-universe: binary packages for Windows and macOS, source on Linux
install.packages(
"pdfium",
repos = c("https://humanpred.r-universe.dev", "https://cloud.r-project.org")
)
# Development version from GitHub (builds from source)
remotes::install_github("humanpred/rpdfium")Installing from source needs a C++17 compiler (Rtools on Windows, the Xcode command-line tools on macOS).
Where the libpdfium binary comes from
Binary packages from r-universe already contain libpdfium. When pdfium is installed from source, the configure script picks a libpdfium to build against, in this order:
-
PDFIUM_HOME— if this environment variable is set and points at an existing install, that install is used. The directory must contain headers and the shared library in the conventional layout:Platform Required files under $PDFIUM_HOMELinux include/fpdfview.handlib/libpdfium.so(orlib64/)macOS include/fpdfview.handlib/libpdfium.dylibWindows include/fpdfview.h,lib/libpdfium.dll.a,bin/libpdfium.dllUseful when you have a hand-built PDFium, a vendored copy, or a CI artefact you want to pin against.
pkg-config --exists libpdfium(POSIX only) — if alibpdfium.pcis on thepkg-configsearch path, the reportedincludedir/libdirare used.Standard system prefixes (POSIX only) —
/usr/local,/usr,/opt/homebrew,/opt/local. The first one containing bothinclude/fpdfview.hand alibpdfiumshared library wins.Download from bblanchon/pdfium-binaries — the pinned release lives in
tools/pdfium-version.txt. If your install runs without internet access, setPDFIUM_OFFLINE=1and place the matching tarball underinst/pdfium-binaries/before installing.
When a system install is found, no download happens and no libpdfium is bundled into the installed package — your existing copy resolves at load time via the platform’s normal shared-library search path.
Example
library(pdfium)
doc <- pdf_doc_open(system.file("extdata", "fixtures", "minimal.pdf",
package = "pdfium"
))
pdf_page_count(doc)
pdf_doc_close(doc)More examples ship in the vignettes (vignette("getting-started", package = "pdfium"), etc.) and on the pkgdown site.
License
pdfium is MIT-licensed. The bundled libpdfium binary is BSD-3-Clause and is not distributed in the source tarball — see LICENSE.md and dev/decisions/ADR-003-binary-distribution.md.