PDFium
Elixir bindings for the pdfium library.
Installing
Add the dependency:
{:pdfium, "~> 0.2"}
Or in a script:
Mix.install([pdfium: "~> 0.2"])
Precompiled NIFs cover OTP 26 and newer on x86_64 and aarch64 Linux, glibc or
musl, and on arm64 macOS. Anywhere else the package compiles from source and
needs a C++ compiler, make and curl.
Usage
Open a document:
{:ok, document} = PDFium.open_document("file.pdf")
Count its pages:
{:ok, pages} = PDFium.get_page_count(document)
Render a page to a file, with Vix:
{:ok, {binary, w, h}} = PDFium.get_page_bitmap(document, 0, 300)
{:ok, image} = Vix.Vips.Image.new_from_binary(binary, w, h, 4, :VIPS_FORMAT_UCHAR)
{:ok, _image} = Image.write(image, "/tmp/sample.png")
Development
Enter the shell, then use mix as usual:
nix develop
mix compile
mix test
mix dialyzer
mix docs
Format the Nix files:
nix fmt
Running tests
Run the tests for every target this machine can run, and dialyzer:
nix flake check
The visual tests compare renders with the images in test/fixtures/visual.
After a change that is meant to draw differently, rewrite them and review the
image diff:
UPDATE_VISUALS=1 mix test --only visual
Build the NIF for a target, or the release archives:
nix build .#nif-aarch64-linux-musl
nix build .#archives
Releasing
From a clean main that matches origin/main, with major, minor or patch:
nix run .#release -- minor
It does what you would by hand:
- Bump
VERSIONand rename the[Unreleased]section ofCHANGELOG.mdto[vX.Y.Z] - YYYY-MM-DD, with a new empty[Unreleased]above it. - Commit.
- Push to
main.
Once the tests pass, CI publishes the package and its docs to Hex and creates
the GitHub release. A release that failed before its tag was created can be
retried by running the CI workflow on main.
Every Monday a workflow opens a pull request that updates libpdfium to its
latest release and notes it in CHANGELOG.md, replacing the previous week's if
it was not merged. Release it like any other change. To get one now:
gh workflow run update-libpdfium.yaml
To update to a specific tag, from your machine:
nix run .#update -- chromium/8152
License
See LICENSE.