Skip to main content

Fast parallel PDF image extractor

Project description

📄 pdfimgextract

pdfimgextract is a high-performance, parallelized Python utility designed for extracting images from PDF documents. Engineered for speed and reliability, it leverages multiprocessing to handle high-throughput workflows with built-in support for deduplication and atomic file operations.


✨ Features

Feature Description
Parallel Extraction Scales workloads across multiple CPU cores using process-based parallelism.
🛡️ Atomic Writes Ensures data integrity by preventing partial file corruption during crashes.
🧹 Deduplication Optional removal of redundant images based on xref or cryptographic hashing.
📊 Progress Tracking Real-time visual feedback via an integrated progress bar.
🛑 Graceful Termination Cleanly handles SIGINT and termination signals to prevent orphaned processes.
💻 Intuitive CLI Streamlined command-line interface for rapid deployment.

📦 Installation

Prerequisites

  • Python 3.10+

Install via pip

pip install pdfimgextract

▶️ Usage

Basic Command

pdfimgextract <input.pdf> <output_dir>

Practical Example

pdfimgextract ./sample.pdf ./output_images

⚙️ Configuration & Options

Argument Description
input.pdf Path to the source PDF file.
output_dir Destination directory for extracted assets.
--parallelism X Number of concurrent worker processes (defaults 8).
--overwrite Force overwrite of existing files in the output directory.
--dedup METHOD Enable image deduplication. Supported methods: xref (default) or hash.

🧵 Concurrency Model

The tool implements a process-based parallelism model to bypass Python's Global Interpreter Lock (GIL) and maximize CPU utilization:

  • Each worker process independently accesses the PDF to extract image streams.
  • Performance Scaling is determined by:
    • CPU core availability and clock speed.
    • Disk I/O throughput (SATA vs. NVMe).
    • Available System RAM.

📁 Output Structure

Extracted images are organized sequentially within the target directory:

output/
├── 0001.png
├── 0002.jpg
├── 0003.png

📊 Performance Benchmarks

A comprehensive evaluation was conducted to measure scalability and efficiency across varying process counts.

🖥️ Test Environment

  • CPU: Intel64 Family 6 Model 183 Stepping 1, GenuineIntel (20C/28T)
  • RAM: 63.8 GB
  • OS: Windows 11 (Build 10.0.26200)
  • Disk: KINGSTON SA400S37480G

📄 Dataset Profile

  • Input: 491 MB PDF
  • Payload: 230 Images (Range: 2MB – 10MB per image)

📈 Results Table

Processes Avg (s) Median (s) Std Dev RAM (MB) Speedup Efficiency Throughput
1 112.92 112.88 0.17 355 1.00x 100.0% 4.35 MB/s
2 58.20 58.23 0.52 637 1.94x 97.0% 8.44 MB/s
4 33.89 33.55 0.96 1,182 3.33x 83.3% 14.49 MB/s
8 21.80 21.04 1.17 2,302 5.18x 64.8% 22.53 MB/s
16 15.17 15.15 0.06 4,506 7.45x 46.5% 32.38 MB/s
32 11.73 11.72 0.07 7,476 9.63x 30.1% 41.88 MB/s

🧠 Performance Insights

  • Linear Scaling: Observed primarily at lower process counts (1–4 workers).
  • Diminishing Returns: Gains begin to plateau beyond 16 processes as the bottleneck shifts from CPU to Disk I/O and Process Management Overhead.
  • Sweet Spot: Optimal efficiency/resource balance is typically found between 8 and 16 workers for this hardware configuration.
  • Maximum Throughput: Peak data processing occurs at 32 workers, albeit at the cost of significantly higher memory consumption and lower per-core efficiency.

📁 Validation

The benchmarking script is available for inspection and reproduction within the docs/ directory of this repository.


⚠️ Limitations

  • Hardware Bound: Overall speed is heavily contingent on storage latency (NVMe recommended for peak performance).
  • Memory Footprint: High process counts with large PDFs can lead to substantial RAM usage.
  • Deduplication Overhead: Enabling hash-based deduplication adds a computational layer that may slightly increase processing time.

🤝 Contributing

Contributions drive improvement! If you encounter bugs or have architectural suggestions, please open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfimgextract-1.6.6.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

pdfimgextract-1.6.6-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file pdfimgextract-1.6.6.tar.gz.

File metadata

  • Download URL: pdfimgextract-1.6.6.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pdfimgextract-1.6.6.tar.gz
Algorithm Hash digest
SHA256 c55eebc7c35950cd5552ec1a6af686a0242ee2b6e1bb310578fd6a3a55a798b7
MD5 ed6cb5cc36e39b234e1716eeb82ac4ab
BLAKE2b-256 6a8fc7953d10dc7dc1781254f10922e2aa5feab125b59ed27f044971f97a714c

See more details on using hashes here.

File details

Details for the file pdfimgextract-1.6.6-py3-none-any.whl.

File metadata

  • Download URL: pdfimgextract-1.6.6-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pdfimgextract-1.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 31b225d9a73ffed14dd2af2f1583574c7eda766c7d08685093f40495271c0e85
MD5 12d5393459a2c25e029084efcc9177c6
BLAKE2b-256 25e8461f39f1f7a5762f2843cf62d30d0eee5f3ccd1f9792241a6619465078c5

See more details on using hashes here.

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