PDF300

How to Compress Many PDFs at Once (Batch Compression Guide)

Updated · 4 min read · By

Compressing one PDF is easy. Compressing forty of them, consistently, without babysitting each file, is a different job. This guide covers folder-level batch compression with a loop, how to keep settings uniform, and the point where a one-by-one target-size tool beats a bulk script.

The situation

You have a folder full of PDFs: scanned invoices, exported reports, a backlog of documents headed for an archive or a shared drive. Opening each one and compressing it by hand would take an afternoon. You want to point a single command at the folder and walk away, with every file coming out smaller and looking the same as its neighbors.

Why batch compression needs consistent settings (the mechanism)

When you compress files one at a time by hand, each file quietly gets different treatment. One ends up at a different image resolution, another keeps full-quality photos, a third gets flattened. The folder becomes a patchwork.

A batch is valuable precisely because it applies one rule to everything. You pick a single quality profile, and the loop runs it against every file. The output is predictable: you know the whole folder went through the same downsampling and the same stream compression. That consistency matters more than squeezing each individual file to its theoretical minimum, because it makes the result reviewable and repeatable.

The catch is that one rule cannot know that report-A.pdf is mostly text and scan-B.pdf is a stack of photos. A single profile is a compromise across the whole set. That is the trade-off you accept for speed and uniformity.

How to batch compress a folder

Method 1: A Ghostscript loop over every PDF

Ghostscript's pdfwrite device with a PDFSETTINGS profile is the workhorse. Loop over the folder and write each result to an output directory so you never overwrite an original:

mkdir -p compressed
for f in *.pdf; do
  gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 \
     -dPDFSETTINGS=/ebook \
     -dNOPAUSE -dBATCH -dQUIET \
     -o "compressed/$f" "$f"
done

/ebook targets a moderate, readable quality. Swap to /screen for smaller, lower-resolution output or /printer for higher quality. Because the profile is set once at the top, every file is treated identically.

Method 2: Recurse through subfolders

If the PDFs are spread across nested directories, use find and mirror the structure into an output tree:

find . -type f -name '*.pdf' -print0 | while IFS= read -r -d '' f; do
  out="compressed/$f"
  mkdir -p "$(dirname "$out")"
  gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook \
     -dNOPAUSE -dBATCH -dQUIET -o "$out" "$f"
done

Method 3: Compare sizes after the run

A batch is only done when you have checked it worked. A quick before-and-after sanity check:

du -sh . compressed

If a few files barely shrank, they are probably image-heavy and need a stronger profile or individual attention.

When a per-file target-size tool is better

A loop applies one quality setting; it does not aim at a file size. If your real requirement is "every file must be under 10 MB" — for a portal, an email, or an upload form — a quality profile is the wrong tool, because /ebook might leave one file at 14 MB and crush another to 300 KB.

For hard size limits, handle those specific files individually with a tool that targets a number instead of a quality preset. PDF300 lets you enter the target size and compresses to fit it, so a file that must be under a limit actually lands there. Use the loop for the bulk, and the target-size tool for the handful that have a strict ceiling.

Checklist

FAQ

Can I run one command to compress every PDF in a folder?

Yes. A shell for loop over *.pdf that calls Ghostscript's pdfwrite device applies the same compression to every file in the folder. Write the results to a separate output directory so your originals stay intact, and add -dBATCH -dNOPAUSE -dQUIET so it runs unattended.

Why do some files barely shrink in a batch?

A single quality profile downsamples images to a fixed resolution and re-compresses streams, but it cannot adapt to each file. A text-only PDF has little to remove, and a file already at low resolution will not shrink further. Those files are not broken; they are simply already near their floor for that profile.

Should I use a batch loop or a target-size tool?

Use a batch loop when you want uniform quality across many files quickly. Use a target-size tool when specific files must each come in under a fixed byte limit, because a quality profile aims at appearance, not at a number, and cannot guarantee a file lands below a ceiling.

Written by LeDeuxions, an architect who built PDF300 after a 300 MB portal limit kept rejecting drawing sets. Figures quoted from third parties link to their source; sizes and reductions described as "typical" are estimates, not guarantees.