Skip to main content
OctopusPDF Guide

The Do-It-Yourself Guide to JPG to PDF Free Conversion Using Python Libraries

The Do It Yourself Guide to JPG to PDF Free Conversion Using Python Libraries TL;DR Best for mixed batches and image editing: Pillow PIL — free, offline, and th…

TL;DR

  • Best for mixed batches and image editing: Pillow (PIL) — free, offline, and the only one of the two that can resize, rotate, crop, or convert color modes before writing pages.
  • Best for pure JPEG sets: img2pdf — one line of code or one shell command, and it embeds JPEG data without re-encoding, so files stay small and pixels stay intact.
  • Best for zero setup: a browser-based converter that processes files locally — no Python, no install, no upload.
  • The trade-off in one line: Pillow gives control, img2pdf gives simplicity and byte-fidelity, the browser gives speed.
  • Privacy: both Python libraries run entirely on your machine; browser tools vary, so confirm local processing before feeding them sensitive scans.

For anyone searching for JPG to PDF free conversion, the practical answer is that img2pdf is the best default for a folder of JPEGs, Pillow is the right choice the moment your images need editing first, and a locally-processing browser converter wins whenever installing a Python runtime costs more time than the task deserves.

This guide compares the two Python routes head to head — Pillow (PIL) versus img2pdf — on the dimensions that actually change your decision: cost, output fidelity, speed, ease of use, privacy, and control. It then maps each option to the reader profiles that benefit most.

At a Glance

  • Pillow (Option A) is a general-purpose imaging library. Writing a PDF means opening each JPG, normalizing it, and calling save("out.pdf", save_all=True, append_images=[...]). You get maximum control over resizing, color mode, rotation, and page ordering.
  • img2pdf (Option B) is a purpose-built wrapper. One convert() call (or one CLI command) turns a list of JPEGs or PNGs into a PDF, and — per its own documentation — it is designed to embed JPEG streams into the PDF container without decoding and re-encoding them.
  • Both are free and open source, both run entirely offline on your machine, and neither imposes page counts or subscription tiers. The real trade-off is control versus simplicity.
  • No-code fallback: if installing Python and a virtual environment is more work than the task deserves, a browser converter that runs locally can combine JPG/PNG images into a single PDF, one image per page, in the order you choose, with the files never leaving your device.

Comparison Dimensions

Both options are judged on the same seven criteria, so the comparison stays symmetrical:

  1. Cost and licensing — what you pay and what the license permits.
  2. Output fidelity and file size — whether pixels are re-encoded and how large the PDF gets.
  3. Speed and performance at scale — behaviour from 5 images to 500.
  4. Setup, syntax, and ease of use — install steps and lines of code.
  5. Privacy — where your files are processed.
  6. Limits and control — page size, transforms, error handling, extensibility.
  7. Ecosystem — what you can reach for when the task grows.

Side-by-Side

Dimension 1: Cost and Licensing

  • A (Pillow): Free and open source, no per-file cost, no account. Its permissive licensing makes it easy to bundle inside internal tools and shipped products. (Judgment: check the current license text in the repository before redistribution.)
  • B (img2pdf): Also free and open source, also no per-file cost. It is distributed under a copyleft-style license, which is fine for internal scripting but worth reading if you plan to ship it inside a closed product.

Winner: Tie on price — both are genuinely free. Pillow is the easier one to redistribute.

Dimension 2: Output Fidelity and File Size

  • A (Pillow): Saving through a general imaging library means images typically pass through an encoder path. Pillow's PDF plugin writes RGB pages as JPEG-compressed (DCTDecode) streams by default, so a source JPG is decoded and re-encoded unless you raise the quality setting with save(..., quality=...); confirm the behaviour for your installed version in Pillow's PDF handling documentation before relying on it. (Judgment, based on the documented PDF save path.)
  • B (img2pdf): Built around lossless embedding — img2pdf's documentation states that JPEG data is placed into the PDF container rather than decoded and re-compressed, which avoids generation loss and usually yields a smaller file for photo-heavy sets. Note that the "lossless" claim applies to JPEG inputs specifically; PNG inputs are encoded into a PDF-compatible stream.

Winner: img2pdf, when your inputs are already JPEGs and you care about fidelity and size. Pillow wins instead when you want re-encoding (for example, converting CMYK scans to RGB or downscaling oversized photos).

Dimension 3: Speed and Performance at Scale

  • A (Pillow): Each image is decoded into memory and re-encoded, so a batch of 500 large photos costs real CPU time and RAM unless you write your own streaming or multiprocessing loop. (Judgment, based on how the library's PDF path works.)
  • B (img2pdf): Because it wraps compressed streams, per-page work is lighter; a few hundred JPEGs convert quickly on a laptop. PNG inputs still require encoding into the PDF's allowed filters, so the advantage is largest for JPEG-heavy folders.

Winner: img2pdf for bulk JPEG batches. For a handful of images, the difference is not worth optimizing.

Diagram showing a source JPG file being wrapped losslessly into a PDF page by img2pdf, versus being decoded and re-encoded by Pillow

Figure 1: The two output paths. img2pdf wraps the existing JPEG stream into the PDF; Pillow decodes the image and writes a new compressed stream, which is why it can resize or rotate but may change file size and byte content.

Dimension 4: Setup, Syntax, and Ease of Use

  • A (Pillow): pip install Pillow, then roughly four lines. The one non-obvious detail is that multi-page output requires save_all=True and append_images; without them you silently get a single-page PDF.
from PIL import Image

paths = ["01.jpg", "02.jpg", "03.jpg"]
images = [Image.open(p).convert("RGB") for p in paths]
images[0].save("out.pdf", save_all=True, append_images=images[1:], resolution=150)
  • B (img2pdf): pip install img2pdf, then one call — and the same operation is available as a command-line tool for shell scripts.
import img2pdf

with open("out.pdf", "wb") as f:
    f.write(img2pdf.convert(["01.jpg", "02.jpg", "03.jpg"]))
img2pdf 01.jpg 02.jpg 03.jpg -o out.pdf

Winner: img2pdf for raw simplicity and scripting; Pillow for anyone who needs per-image logic before the save.

Dimension 5: Privacy and Where Your Files Go

  • A (Pillow): Runs in your Python process. Nothing is uploaded, because there is no network code in the conversion path.
  • B (img2pdf): Same story — a local library call, no remote service.
  • No-code comparison: browser-based converters differ sharply here. Some process files locally in the page and never upload them, while others push the file to a server. Read the tool's own description before dropping a passport scan into it.

Winner: Tie between the two libraries — this is the strongest argument for either of them when the JPGs are sensitive.

Dimension 6: Limits, Control, and Extensibility

  • A (Pillow): No hard page or size cap beyond your machine. You can rotate, crop, resize, convert color modes, set page resolution, and mix in text or stamps by pairing it with a PDF-generation library such as reportlab. Every page you add is something you explicitly constructed.
  • B (img2pdf): Deliberately narrow. It exposes layout options such as page size and DPI handling, but it is not the tool for watermarking or merging text pages. PNG inputs are converted into PDF-compatible streams, which is where the "lossless" promise is limited to JPEG sources.

Winner: Pillow, clearly, for anything beyond straight conversion.

Other Free Options Worth Knowing

The libraries above are not the only route, and the alternatives are worth weighing before you commit to writing code:

  • reportlab — useful when the PDF must contain text, headers, or generated page numbers alongside the images. More code, more output control.
  • ImageMagick — magick 01.jpg 02.jpg out.pdf converts images from the shell. Some Linux distributions ship a policy file that blocks PDF writing by default, so check before scripting it into a pipeline.
  • Operating-system "print to PDF" — zero dependencies, but image ordering and page sizing are manual and tedious beyond a few files.
  • Local browser converters — the fastest path when you cannot or will not install a runtime; the trade-off is less automation and no reproducible script.
Screenshot of a browser-based JPG to PDF converter interface showing drag-and-drop page ordering and a local-processing notice

Figure 2: A no-install fallback in action — pages can be reordered before export, and tools that process locally keep the images on your device instead of uploading them.

Feature Table

Feature Option A: Pillow Option B: img2pdf
Cost Free, open source Free, open source
Install pip install Pillow pip install img2pdf
Typical code length ~4–6 lines 1–2 lines or 1 CLI command
Lossless JPEG embedding Not the design goal; re-encodes by default Documented design goal (JPEG inputs)
Mixed JPG + PNG in one call Yes, with per-image handling Yes
Page order List order you pass List order you pass
Page size / DPI control Yes, via save parameters and resolution Yes, via layout and DPI options
Resize, rotate, crop, color convert Yes No
Add text, stamps, watermarks Via reportlab or similar No
Command-line interface No (write a script) Yes
Runs offline Yes Yes
Best fit Mixed inputs and custom layout Large JPEG sets, lossless, scripted

When to Choose Option A (Pillow)

  • Your folder contains a mix of JPG, PNG, and other formats that need normalizing before conversion.
  • You need to rotate, crop, resize, or convert color modes before the images become PDF pages.
  • The PDF will combine images with generated text, headers, or watermarks, so you are already pulling in reportlab or an equivalent.
  • You want a script you fully control — error handling, logging, custom naming, integration into a larger pipeline.
  • You are comfortable that a general-purpose encoder is doing the writing and will verify the output on a sample file.

When to Choose Option B (img2pdf)

  • Your sources are JPEGs and you want the smallest file without generation loss.
  • You are converting hundreds of photos and want the fastest per-page path.
  • You want one command in a Makefile or CI step rather than a Python script.
  • You do not need any per-image transformation — the images are already how you want them.
  • You are wrapping existing scans or camera output into a single archive PDF.

FAQ

Q1. Do I need Python installed to do JPG to PDF free conversion?

No. Python libraries require a runtime and pip; browser-based converters require nothing but a tab. If you already have Python, both Pillow and img2pdf are one install away. If you do not, the no-code route is faster to first result, though it is harder to automate.

Q2. Does converting a JPG to PDF reduce image quality?

It depends on the tool. A wrapper designed for lossless embedding — img2pdf, for JPEG inputs — keeps the original JPEG data intact, so there is no generation loss. Pillow's PDF path re-encodes by default, which can lose a little quality unless you raise the quality setting, in which case the file grows. Browser tools that place one image per page typically preserve the image as-is.

Q3. How do I keep the pages in the right order?

Build the file list explicitly. Python's sorted() on zero-padded filenames (01.jpg, 02.jpg) is the reliable pattern, because alphabetical sorting of 1.jpg…10.jpg puts 10.jpg before 2.jpg. Both libraries write pages in the order of the list you pass, and browser converters generally let you drag pages into position before export.

Q4. What if I later need the PDF back as images or as text?

Python can handle the reverse direction — libraries such as pdf2image and PyMuPDF render or extract pages — and browser tools exist for the same job. One example is OctopusPDF's PDF to Images, which exports pages as PNG or JPG at 72, 144, or 216 DPI, with 2x described as the sweet spot for most screens, and processes files locally rather than uploading them. The same vendor's PDF to Markdown tool is aimed at LLM workflows, with a free tier of 3 conversions per day for files up to 20 MB and a Pro tier offering unlimited conversions, files up to 100 MB, and batch mode.

Verdict

Choose img2pdf if your job is what it sounds like: a folder of JPEGs that needs to become one PDF, fast, without any change to the pixels and without much code. Choose Pillow if the JPGs need work before they become pages — resizing, rotating, color conversion, mixing formats, or combining with generated text. The two are not competitors so much as adjacent tools, and a mature pipeline often uses both: Pillow to prepare the images, img2pdf or Pillow's own PDF writer to assemble them.

If writing code is the obstacle rather than the goal, the browser route is a legitimate answer to JPG to PDF free conversion and, for sensitive files, preferable to any converter that uploads. The deciding question is simple: do you need a repeatable script, or do you need this one PDF finished in the next two minutes?

Key Facts

  • Pillow writes multi-page PDFs only when you pass save_all=True along with append_images; without those, a multi-image save produces a single-page result.
  • img2pdf is purpose-built for image-to-PDF conversion, embeds JPEG data without re-encoding according to its documentation, and offers both a Python API and a one-line CLI.
  • Both libraries are free and open source, run entirely offline, and impose no page or file-count tiers — the practical limits are your CPU and RAM.
  • Browser-based converters vary on privacy: some process files locally and never upload them, while others send files to a server, so verify before converting sensitive documents.
  • Related conversion directions exist for the same workflow: PDF pages can be exported back to PNG or JPG at 72, 144, or 216 DPI, and PDFs can be converted to Markdown for LLM pipelines, with free tiers typically capped per day and per file size.