Skip to main content

Ultra-fast PDF to PNG converter

Project description

Built for Miruiq — AI-powered data extraction from PDFs and documents.

Miruiq

fastpdf2png

Fast PDF to PNG converter. SIMD-optimized PNG encoding, automatic grayscale detection, multi-process scaling. MIT licensed.

License Platform

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

Worker scaling

Benchmark

How it works

Architecture

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 150 Output resolution
workers 4 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastpdf2png-1.3.1-py3-none-win_amd64.whl (3.6 MB view details)

Uploaded Python 3Windows x86-64

fastpdf2png-1.3.1-py3-none-manylinux_2_17_x86_64.whl (3.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

fastpdf2png-1.3.1-py3-none-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file fastpdf2png-1.3.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: fastpdf2png-1.3.1-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

Hashes for fastpdf2png-1.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 dd01a5d0623aae999f97a4eeb9c61d60cc2dc249373b753e14bc9242e1b13a5d
MD5 680e73908359561b67901cd7dbdb16c2
BLAKE2b-256 867a5593856c0bdfe0f17eb798be80b08dc77ef02f110742a68f2c2acddd3fae

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastpdf2png-1.3.1-py3-none-win_amd64.whl:

Publisher: build.yml on nataell95/fastpdf2png

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastpdf2png-1.3.1-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for fastpdf2png-1.3.1-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d5c631c9a5db4f88ac78f402365e7d63dc9cbaacc3ee72c8f96b9b1852116c6e
MD5 e48f550e97356848665ed343fa00ff3b
BLAKE2b-256 9929ac24d645b0800d107baf4bba0466b96572da1882e1d94e7da58238c2477f

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastpdf2png-1.3.1-py3-none-manylinux_2_17_x86_64.whl:

Publisher: build.yml on nataell95/fastpdf2png

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastpdf2png-1.3.1-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for fastpdf2png-1.3.1-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 eaeca6aa5d2a10f554e3908822d16a0f7fd46acdc66e4511858bd93a676de110
MD5 a4c86d75c6c8e7e8397f938b79da521f
BLAKE2b-256 472b75346998bb52dfdae7a776b213012d0209032266b0b149e433d8c6dc4258

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastpdf2png-1.3.1-py3-none-macosx_15_0_arm64.whl:

Publisher: build.yml on nataell95/fastpdf2png

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page