This is the place of development for a liberal-licensed1 Python PDF rendering library, powered by PDFium.
- CPython >= 3.6 2
Windowsamd64 / arm64 / win32macOSx86_64 / arm64 (11.0+)Linux (glibc)x86_64 / i686 / aarch64 / armv7lLinux (musl)x86_64 / i686 / aarch64Androidarm64_v8a / armeabi_v7a (+ x86_64 / x86 simulators) (experimental)
These are the platforms supported with pre-built pdfium-binaries. In principle, pypdfium2 may run anywhere provided you are able to procure a pdfium build for the platform.3
python3 -m pip install pypdfium2import pypdfium2 as pdfium
# Load a document
pdf = pdfium.PdfDocument("tests/resources/multipage.pdf")
# Loop over pages and render
for i in range(len(pdf)):
page = pdf[i]
image = page.render(scale=4).to_pil()
image.save(f"output_{i:03d}.jpg")- Liberal license (
BSD-3-Clause,Apache-2.0, plus various other open-source licenses for third-party components of PDFium.) - Wide range of supported platforms and Python versions.
- No mandatory runtime dependencies.
- Can process encrypted (password-protected) PDFs.
- Fast rendering (probably outperforming
popplerandghostscript). In terms of speed, pypdfium2 can almost reachpymupdf. - Multiple choices for the rendering return type:
- pypdfium2 repository (with support model code)
- pypdfium2 documentation
- ctypes documentation
- pdfium repository
- pdfium merge requests
- pdfium bug tracker
- pdfium mailing list
For pdfium documentation, please look at the comments in its public header files (public/*.h).
Footnotes
-
Disclaimer: This is not legal advice. While we hope this project is useful to others, there is ABSOLUTELY NO WARRANTY. It is the embedder's responsibility to check on licensing. See also GitHub's disclaimer. ↩
-
PyPy might work but is not tested. ↩
-
Other rare operating systems / CPUs exist, such as
FreeBSD,Illumos,AIX,IBM z/OS,Haiku,SerenityOS/MIPS,SPARC,PowerPC (big-endian),Elbrus 2000, ... but it is not feasible to provide pre-builds for any arbitrary platform under the roof of this project. In particular, to be able to provide builds for a platform, we need at least one of the following:- Google's toolchain handles the platform, and a sysroot is available
- A native GitHub Actions runner is available, or a runner-emulator combination that achives near-native performance (e.g. aarch64 to armv7l, or x86_64 to i686)
- An emulated PyPA container with static clang cross-compiler is available (running on the host architecture, but being pre-configured for cross-compilation to the target architecture), and produces working builds
In addition, pdfium's code itself needs to work on the platform in question (notably, there might be endianness bugs on big-endian CPUs, pdfium's Readme acknowledges this). Building/packaging pdfium for extra platforms that we are not able to support here is down to porting experts or technically accomplished end users from the respective projects. Where the host system provides pdfium and standard
ctypes.util.find_library()means can find it, pypdfium2's setup theoretically should work even on unhandled platforms (if not, please file a bug report). Moreover, on non-covered CPUs of supported OSes, the native sourcebuild should work if system-level dependencies are installed (pypdfium2'ssetup.pywill attempt this as a last resort). ↩