Project to compile PDFium library to multiple platforms.
We are only going to use the wasm binaries for our purposes. You can either utilize a Ubuntu 20.04/22.04/24.04 instance or run a docker container instance. Note that the minor ver .04 is important here as compiling it on a different minor .10 will not work. Alternatively use the docker container to setup the compiling environment beforehand.
NOTE: STEPS 1-3 IS ONLY REQUIRED TO BE RAN ONCE. OTHER STEPS MUST BE RAN EVERY TIME FOR A BUILD.
- Get the source, make sure that it is commit(s) ahead of upstream with
addFunction
,removeFunction
, and-sALLOW_TABLE_GROWTH
part of the wasm compilation exports.
git clone https://github.com/checkersoftware/pdfium-lib.git
cd pdfium-lib
Docker setup for if you are not using a standalone Ubuntu distro.
- Build the image with command (this is for macbooks with M series processors):
docker build --platform linux/amd64 -t pdfium-wasm -f docker/wasm/Dockerfile docker/wasm
- Now you can open an interactive shell for the container with:
docker run --platform linux/amd64 -v ${PWD}:/app -it pdfium-wasm
Run the rest of the commands in this interactive shell.
- Install PIP requirements:
python3 -m pip install -r requirements.txt
- Get Google Depot Tools:
python3 make.py build-depot-tools
export PATH=$PATH:$PWD/build/depot-tools
From here forth only these steps need to be ran for compilation.
-
Get Emscripten SDK:
python3 make.py build-emsdk
-
Execute EMSDK environment file "emsdk_env" according to your system. For us this should be
/emsdk/emsdk_env.sh
-
Get PDFium:
python3 make.py build-pdfium-wasm
-
Patch:
python3 make.py patch-wasm
-
PDFium Linux dependencies
./build/wasm32/pdfium/build/install-build-deps.sh
-
Compile:
python3 make.py build-wasm
-
Install libraries:
python3 make.py install-wasm
-
Test:
python3 make.py test-wasm
-
Generate javascript libraries:
python3 make.py generate-wasm
At this point you should be able to find pdfium.js
and pdfium.wasm
inside ./build/wasm32/wasm/release/node
, those replace the current pdfium.js
and pdfium.wasm
files in our projects.
This project currently compiles to these platforms:
- iOS device (arm64)
- iOS simulator (x86_64, arm64)
- Android (armv7, armv8, x86, x86_64)
- macOS (x86_64, arm64)
- WASM (Web Assembly)
Platforms in roadmap:
- Linux
- Windows
Obs: PDFium project is from Google and i only patch it to compile to all platforms above. Check all oficial details and PDFium license here:
https://pdfium.googlesource.com/
Since this project generate WASM version, i published a demo that you can test PDFium direct on web browser here:
Or with a public PDF as parameter:
- Ninja Build
- Python 3
- PIP
Obs: Generally Python 3 already come with PIP installed. Check it with command python3 -m pip --version
.
Access releases page to download prebuilt binaries:
https://github.com/paulocoutinhox/pdfium-lib/releases
Check tutorial here: How to include files
Support the continuous development of this project.
- XPLPC - Cross Platform Lite Procedure Call: https://github.com/xplpc/xplpc
- Nativium - C++ Multiplatform Modular Toolkit Template: https://github.com/nativium/nativium
This license informations is about this personal project, not the Google PDFium Library.
Copyright (c) 2018-2024, Paulo Coutinho