PDFium
Native bindings for pdfium project
Installing
for Mix projects, add the following under
depsinmix.exs:{:pdfium, "~> 0.1"}for single-file Elixir scripts, add the following:
Mix.install([pdfium: "~> 0.1"])
Usage
open a PDF file descriptor:
{:ok, document} = PDFium.load_document("file.pdf") # => {:ok, #Reference<0.2181297728.2193227786.166499>}get the number of pages in the file:
{:ok, pages} = PDFium.get_page_count(document) # => {:ok, 1}render a page to file:
{:ok, ref} = PDFium.load_document("/Users/eugene/Downloads/7ade6db09604a8b41104763c6f16a987.pdf") {:ok, binary, w, h} = PDFium.get_page_bitmap(ref, 0, 300) # 300 for DPI {:ok, image} = Vix.Vips.Image.new_from_binary(binary, w, h, 4, :VIPS_FORMAT_UCHAR) {:ok, _image} = Image.write(image, "/tmp/sample.png")
Releasing
bump version in
VERSIONfile. Run:echo -n (awk 'BEGIN{FS=OFS="."} {$NF+=1}1' VERSION) > VERSIONcommit and push the change:
git add VERSION git commit --message "Bump library version" git push origin maincreate a PR from
maintostable. Run:gh pr create --base stable --fillwait until the PR checks are green, then merge the PR
Running CI steps locally
Prepare:
mkdir outputBuild:
dagger call \ precompile --src-dir . --platform-name linux/arm64 --abi musl \ export --path output/ --allowParentDirPathTest:
dagger call test \ --precompiled output/pdfium-nif-2.17-aarch64-linux-musl-0.1.23.tar.gz \ --abi musl --platform-name linux/arm64
Known issues
-
Installing the library was tested and will work in macOS and inside Docker images built by Bob. Installing
currently doesn't work under Elixir installed via package managers, such as via
apk add elixirfor example.
License
See [LICENSE].