img2pdf
Lossless conversion of raster images to PDF.
What it is and what it does
img2pdf is a Python library and command-line tool that converts raster images into PDF files while preserving image quality and minimizing file size. Unlike general-purpose image converters, it avoids re-encoding pixel data whenever possible—for JPEG, JPEG2000, PNG, TIFF, and JBIG2 formats, the image data is embedded directly into the PDF container with only minimal PDF overhead added. For other formats or color spaces, it applies appropriate compression filters (PNG Paeth, CCITT Group 4, or flate) before embedding.
The package works both as a standalone command-line tool and as a Python library. It handles single images, multiple images, and batch operations from directories or glob patterns. It depends on Pillow for image metadata extraction and format conversion when needed, and pikepdf for PDF handling. The tool is designed to handle large images efficiently by avoiding full decompression into memory during the conversion process.
Use it for:
- Batch convert a folder of photographs to PDF without quality loss or file bloat for archival or sharing.
- Create a multi-page PDF from a sequence of scanned document images while preserving original resolution.
- Embed images directly into PDF containers from a Python script with minimal overhead and maximum speed.
- Process JPEG or PNG images to PDF in a pipeline (e.g., from a scanner or camera) without intermediate re-encoding.
- Handle CMYK or monochrome images that require specific PDF encoding while keeping file sizes small.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts raster images to PDF without re-encoding pixel data, prioritizing lossless output, small file size, and speed by embedding images directly into the PDF container when possible.
Yes. The package fills a specific, well-defined niche: lossless image-to-PDF conversion with minimal file size and fast processing. Low install friction, no security vulnerabilities, and broad format support make it a solid choice for image-to-PDF workflows. The copyleft license is a minor consideration only if you plan to redistribute derivative code. Aging maintenance status (282 days since last release) is not a blocker for a stable, mature tool, but monitor for any future issues.
Install
img2pdf on PyPI
pip
pip install img2pdfuv
uv add img2pdfpoetry
poetry add img2pdfInstalling img2pdf
Before you install
Low friction install with two stable runtime dependencies (Pillow and pikepdf). Package shows aging maintenance status with last release 282 days ago, but has been actively maintained since 2014 and supports current Python versions.
License in practice
Licensed under LGPLv3 (copyleft). You may use and modify the package freely, but any derivative works must also be licensed under LGPLv3 and source code must be made available.
Quickstart
pip install img2pdf
import img2pdf
with open("output.pdf", "wb") as f:
f.write(img2pdf.convert('input.jpg'))
Input images must be provided as files or file handles; img2pdf needs to seek in the file descriptor and cannot work from pure in-memory byte streams alone.
Verify before relying
- Whether pikepdf is always required or only for certain image formats or operations
- Performance characteristics on very large images relative to other tools
- Compatibility with all PDF readers for directly-embedded formats beyond Adobe Acrobat Reader
Package facts
| License | not declared (copyleft) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — Pillow, pikepdf |
| Maintenance | aging — 282 days since the last release |
| First released | |
| Downloads | 2,325,033/month — #3,139 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: img2pdf-0.6.3-py3-none-any.whl
Tags
More Graphics packages
Pillow adds image processing capabilities to…
permissive · top 100 on PyPI
fonttoolsfonttools manipulates font files in multiple…
permissive · top 1,000 on PyPI
matplotlib-inlineEnables matplotlib figures to display inline…
permissive · top 1,000 on PyPI
pymupdfPyMuPDF extracts, renders, converts, and…
agpl · top 1,000 on PyPI
pypdfium2pypdfium2 is a Python binding to PDFium that…
permissive · top 1,000 on PyPI
altairAltair is a declarative Python library for…
permissive · top 1,000 on PyPI
fpdfGenerates PDF documents from Python code,…
copyleft · top 5,000 on PyPI
rawpyrawpy wraps LibRaw to load, decode, and…
permissive · top 15,000 on PyPI
pdf2imageConverts PDF files to PIL Image objects by…
permissive · top 1,000 on PyPI
pyjpeglsEncodes and decodes image data using the…
permissive · top 15,000 on PyPI
vtracerConverts raster images (JPG, PNG) into vector…
permissive · top 15,000 on PyPI
pylibjpeg-openjpegDecodes and encodes JPEG 2000 images to and…
permissive · top 15,000 on PyPI
pylibjpegDecodes and encodes JPEG, JPEG-LS, JPEG 2000,…
permissive · top 15,000 on PyPI
PyTurboJPEGPyTurboJPEG wraps libjpeg-turbo to decode and…
permissive · top 15,000 on PyPI
empty-filesCreates minimal valid empty files of various…
permissive · top 15,000 on PyPI
pyvipsPython binding for libvips, a streaming image…
permissive · top 15,000 on PyPI