Ultra-fast PDF to PNG converter
Project description
Built for Miruiq — AI-powered data extraction from PDFs and documents.
fastpdf2png
Fast PDF to PNG converter. SIMD-optimized PNG encoding, automatic grayscale detection, multi-process scaling. MIT licensed.
Install
pip install fastpdf2png
Or build from source:
git clone https://github.com/nataell95/fastpdf2png.git && cd fastpdf2png
bash scripts/build.sh
Usage
CLI
./build/fastpdf2png input.pdf page_%03d.png 300 4 -c 2
Python
import fastpdf2png
images = fastpdf2png.to_images("doc.pdf") # list of PIL images
fastpdf2png.to_files("doc.pdf", "output/") # save PNGs to disk
data = fastpdf2png.to_bytes("doc.pdf") # raw PNG bytes
n = fastpdf2png.page_count("doc.pdf") # page count
# Batch processing — keep PDFium loaded between calls
with fastpdf2png.Engine() as pdf:
for path in my_pdfs:
images = pdf.to_images(path, dpi=150)
Node.js
const pdf = require("fastpdf2png");
pdf.toFiles("doc.pdf", "output/", { dpi: 150 });
const buffers = pdf.toBuffers("doc.pdf");
const count = pdf.pageCount("doc.pdf");
// Batch processing
const engine = new pdf.Engine();
await engine.toFiles("doc.pdf", "output/");
engine.close();
Performance
How it works
Rendering
Google's PDFium (the engine inside Chromium) renders each page into a raw BGRA bitmap in memory. This gives us pixel-perfect output identical to what Chrome displays.
Grayscale detection
Before encoding, a SIMD-accelerated pass scans every pixel to check if R == G == B. Most document pages (text, tables, charts) are grayscale — detecting this lets us encode them as 8-bit PNG instead of 24-bit RGB, cutting data size by 66% with zero quality loss. On ARM this uses NEON vld4/vceq intrinsics; on x86 it uses SSE/AVX2.
PNG encoding
Instead of the standard zlib/libpng pipeline, we use a patched libdeflate with a modified hash-skip optimization that skips redundant hash table insertions for long matches (+45% throughput). The compressed data goes directly into a pre-allocated output buffer — the PNG header, IDAT chunk, and IEND trailer are assembled around it with zero intermediate copies. CRC32 checksums are computed using hardware-accelerated instructions (CRC32 on ARM, PCLMUL on x86).
Parallelism
PDFium is not thread-safe, so we use fork() to create isolated worker processes. Each worker shares a single atomic page counter via mmap'd shared memory — workers grab the next unprocessed page with fetch_add, render it, and write the PNG to disk. Copy-on-write semantics mean the PDFium library and document data are shared across workers without duplicating memory.
Thread-local pools
Each worker maintains thread-local memory pools for pixel buffers and compression scratch space. After the first page warms up the pools, subsequent pages require zero malloc/free calls in the hot path.
CLI reference
fastpdf2png <input.pdf> <output_%03d.png> [dpi] [workers] [-c level]
fastpdf2png --info <input.pdf>
fastpdf2png --daemon
| Flag | Default | Description |
|---|---|---|
dpi |
300 | Output resolution |
workers |
1 | Parallel processes |
-c 0/1/2 |
2 | Compression: fast / medium / best |
--info |
Print page count | |
--daemon |
Persistent mode (stdin commands) |
Platforms
| OS | Arch | SIMD |
|---|---|---|
| macOS | arm64 | NEON |
| macOS | x86_64 | AVX2, SSE4.1 |
| Linux | x86_64 | AVX2, SSE4.1 |
| Linux | arm64 | NEON |
| Windows | x86_64 | AVX2, SSE4.1 |
License
MIT. See LICENSE and THIRD_PARTY_LICENSES.md.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastpdf2png-1.3.0-py3-none-win_amd64.whl.
File metadata
- Download URL: fastpdf2png-1.3.0-py3-none-win_amd64.whl
- Upload date:
- Size: 3.6 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dccfe655ccdd563506607f0d89f8b30141f45954f1553b2e2de2319817c5f70f
|
|
| MD5 |
68d9054bc161219fed41e52a6ee9e92e
|
|
| BLAKE2b-256 |
30c2cf7ae5939be77389cdc44f7c5844ab7c113f43c076b978363f58badca5e0
|
Provenance
The following attestation bundles were made for fastpdf2png-1.3.0-py3-none-win_amd64.whl:
Publisher:
build.yml on nataell95/fastpdf2png
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastpdf2png-1.3.0-py3-none-win_amd64.whl -
Subject digest:
dccfe655ccdd563506607f0d89f8b30141f45954f1553b2e2de2319817c5f70f - Sigstore transparency entry: 1128446185
- Sigstore integration time:
-
Permalink:
nataell95/fastpdf2png@00b6606fdb9e4e9f724fe565aea95499b248230c -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/nataell95
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@00b6606fdb9e4e9f724fe565aea95499b248230c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastpdf2png-1.3.0-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: fastpdf2png-1.3.0-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86d42b1b607ec125d4d1ec63e5bd16e96f114bad54a09f62c327f7c0350aef2c
|
|
| MD5 |
24c3f0e6e457cf70c4e34dda48cfd801
|
|
| BLAKE2b-256 |
c64c7a25fc82fdd878b69be2ec0be7e9b78c3b5a93fc26dbb2fdfe5fc6a80c11
|
Provenance
The following attestation bundles were made for fastpdf2png-1.3.0-py3-none-manylinux_2_17_x86_64.whl:
Publisher:
build.yml on nataell95/fastpdf2png
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastpdf2png-1.3.0-py3-none-manylinux_2_17_x86_64.whl -
Subject digest:
86d42b1b607ec125d4d1ec63e5bd16e96f114bad54a09f62c327f7c0350aef2c - Sigstore transparency entry: 1128445959
- Sigstore integration time:
-
Permalink:
nataell95/fastpdf2png@00b6606fdb9e4e9f724fe565aea95499b248230c -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/nataell95
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@00b6606fdb9e4e9f724fe565aea95499b248230c -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastpdf2png-1.3.0-py3-none-macosx_15_0_arm64.whl.
File metadata
- Download URL: fastpdf2png-1.3.0-py3-none-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: Python 3, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
053da809ab3dc3826c9623d7f5941c5f2c65a8deb9b8ff67f42eb15199390998
|
|
| MD5 |
c7f10c35129b93ec0abd854b06298888
|
|
| BLAKE2b-256 |
98a110eb025ca3a2a5b534ebebdcbd443c0522495b42ce876acbbf038a87542a
|
Provenance
The following attestation bundles were made for fastpdf2png-1.3.0-py3-none-macosx_15_0_arm64.whl:
Publisher:
build.yml on nataell95/fastpdf2png
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastpdf2png-1.3.0-py3-none-macosx_15_0_arm64.whl -
Subject digest:
053da809ab3dc3826c9623d7f5941c5f2c65a8deb9b8ff67f42eb15199390998 - Sigstore transparency entry: 1128445855
- Sigstore integration time:
-
Permalink:
nataell95/fastpdf2png@00b6606fdb9e4e9f724fe565aea95499b248230c -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/nataell95
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@00b6606fdb9e4e9f724fe565aea95499b248230c -
Trigger Event:
push
-
Statement type: