Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

212.3. pdfium-7988

Chromium's PDF renderer, as a shared library with its C headers

Version 7988, release 1
Shelf documents — PDF, PostScript, DjVu, EPUB, CHM and DOCX viewers, libraries and tools, and ebook managers
Phase 42_graphics (Graphics Stack), 84 of 189 in build order
Licence BSD-3-Clause AND Apache-2.0
Homepage https://pdfium.googlesource.com/pdfium/
Build time 4.7 SBU
Installed size 5.1 MiB in 28 files
Recipe ports/core/documents/pdfium/kpkgbuild

About

PDFium is Chromium’s PDF engine. KDOS builds it as a shared library, libpdfium.so, with its C headers under /usr/include/pdfium and two pkg-config files, for the two ports that use it: python3-pypdfium2, the Python binding that OCRmyPDF renders pages with, and libvips’s PDF loader. The port’s version is the PDFium branch number, which is also the build number of the Chromium release it belongs to (_chromium in the recipe).

Why it is in KDOS

The comment above it in script/phases/42_graphics/packages.d/documents.txt:

ocrmypdf's rasteriser: Chromium's PDF engine built as a shared library.

Sources

Dependencies

Depends on: gn, ninja, python3, pkgconf, freetype2, harfbuzz, icu, lcms2, libjpeg-turbo, libpng, openjpeg, zlib.

Required by (2): libvips, python3-pypdfium2.

Patches

build.sh applies these; kpkg applies nothing by itself.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/42_graphics/phase.env && kpkg install pdfium'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/documents/pdfium.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/documents/pdfium
echo '0340b2fca57cecdf6e2e0366129a3340f6764c132cb090f57db96d9f0f349855  pdfium-7988.tar.bz2' | sha256sum -c -
echo '4268f9778821e4aa45e21ba2ca21641aacc4657bfa01692232b89ed64ad07546  pdfium-vendor-7988.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/pdfium
SRC=$SRC_ROOT/pdfium-7988
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf pdfium-7988.tar.bz2 -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _chromium, _build_rev, _abseil_rev and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

for pin in "build_revision=$_build_rev" "abseil_revision=$_abseil_rev"; do
	if ! grep -q "'${pin%%=*}': '${pin#*=}'" DEPS; then
		echo "pdfium: DEPS does not name ${pin%%=*} ${pin#*=} — rebuild the vendor bundle" >&2
		exit 1
	fi
done
rm -rf third_party/abseil-cpp
tar -xf "$PORT_SRC/$name-vendor-$version.tar.xz" --strip-components=1

patch -p1 -i "$PORT_SRC/pdfium-shared-library.patch"

printf 'build_with_chromium = false\n' > build/config/gclient_args.gni
install -Dm644 build/linux/unbundle/icu.gn third_party/icu/BUILD.gn

export CC=gcc CXX=g++ AR=ar NM=nm
export CPPFLAGS="$CPPFLAGS -ffp-contract=off"

gn gen out/Release --root-pattern=//:pdfium --args='
  is_debug = false
  is_clang = false
  is_component_build = false
  custom_toolchain = "//build/toolchain/linux/unbundle:default"
  host_toolchain = "//build/toolchain/linux/unbundle:default"
  treat_warnings_as_errors = false
  clang_use_chrome_plugins = false
  use_custom_libcxx = false
  use_sysroot = false
  use_glib = false
  use_siso = false
  pdf_is_standalone = true
  pdf_enable_v8 = false
  pdf_enable_xfa = false
  pdf_use_skia = false
  pdf_use_partition_alloc = false
  pdf_bundle_freetype = false
  use_system_freetype = true
  use_system_harfbuzz = true
  use_system_lcms2 = true
  use_system_libjpeg = true
  use_system_libopenjpeg2 = true
  use_system_libpng = true
  use_system_libtiff = true
  use_system_zlib = true
'
ninja -C out/Release pdfium

install -Dm755 out/Release/libpdfium.so "$PKG/usr/lib/libpdfium.so"
install -d "$PKG/usr/include/pdfium/cpp"
install -m644 public/*.h "$PKG/usr/include/pdfium/"
install -m644 public/cpp/*.h "$PKG/usr/include/pdfium/cpp/"

install -Dm644 /dev/stdin "$PKG/usr/lib/pkgconfig/libpdfium.pc" <<PC
prefix=/usr
libdir=\${prefix}/lib
includedir=\${prefix}/include/pdfium

Name: libpdfium
Description: Chromium's PDF renderer
Version: $_chromium
Libs: -L\${libdir} -lpdfium
Cflags: -I\${includedir}
PC

install -Dm644 /dev/stdin "$PKG/usr/lib/pkgconfig/pdfium.pc" <<PC
prefix=/usr
libdir=\${prefix}/lib
includedir=\${prefix}/include/pdfium

Name: pdfium
Description: Chromium's PDF renderer
Version: $version
Libs: -L\${libdir} -lpdfium
Cflags: -I\${includedir}
PC
install -Dm644 LICENSE "$PKG/usr/share/licenses/$name/LICENSE"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/pdfium, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf pdfium-7988-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/pdfium, and runs the triggers its paths call for.

Contents

Installed libraries: libpdfium.so.

Installed directories: /usr/include/pdfium, /usr/share/licenses/pdfium.

Short descriptions

libpdfium.pc Chromium's PDF renderer
pdfium.pc Chromium's PDF renderer

Notes