Automation Guide

Batch Unlock Multiple PDFs — Automation Guide

Unlocking a single PDF is straightforward when you know the password. When you need to process 50, 500, or 5,000 encrypted PDFs — perhaps from an old corporate document management system, a pre-2010 archive, or a deceased employee's file server — automation becomes essential. This guide covers batch approaches for three scenarios: (a) all files share the same password, (b) each file has its own password but you know them, and (c) the passwords are all unknown (batch cracking). We cover QPDF, hashcat, Python scripting, and shell pipelines for each scenario.

Scenario 1 — Same password for all files

Many organisations use a single document-level password for all internal PDFs. If you know that password, batch unlocking is trivial. Use QPDF's --decrypt flag in a shell loop: for f in *.pdf; do qpdf --decrypt --password=THEPASSWORD "$f" "unlocked_$f"; done

On Windows: Get-ChildItem *.pdf | ForEach-Object { qpdf --decrypt --password=THEPASSWORD $_.Name "unlocked_$($_.Name)" }. QPDF is available on all platforms via conda, apt, or the QPDF website.

Performance: qpdf decryption is CPU-bound, so throughput scales with the number of cores you run in parallel; for large files disk I/O becomes the limiting factor. Rather than extrapolating from a rule-of-thumb rate, benchmark a few hundred representative files from your own batch and size the job from that.

Verify each output: QPDF exits with code 0 on success and non-zero on failure. Check exit codes in the shell loop and log failures for manual review. Files that fail with the shared password may have a different password or be corrupted.

Parallel batch processing

Use GNU parallel or xargs -P to process multiple files concurrently. qpdf is CPU-bound, so match thread count to CPU cores: ls *.pdf | parallel -j$(nproc) qpdf --decrypt --password=THEPASSWORD {} unlocked_{}

Scenario 2 — Known passwords per file (password map)

If you have a password map (spreadsheet or CSV mapping filename to password), automate with a Python script. Read the CSV, iterate over files, and apply qpdf with the per-file password. Python's subprocess module runs qpdf and captures exit codes.

Sample approach: read a 'passwords.csv' with columns 'filename,password'. For each row, call qpdf --decrypt --password=ROW_PASSWORD. Log success/fail per file to an output CSV. Files that fail may indicate the password is wrong in the map — flag them for manual review.

This scenario is common in enterprise content migration projects where the document management system stores per-document passwords in a database. Export the password table as CSV, match by filename, and run the batch decrypt. Expect throughput below the plain shell loop, because each file also spawns a qpdf process and performs a lookup — benchmark your own set before committing to a schedule.

Scenario 3 — All passwords unknown (batch cracking)

When none of the passwords are known, you need batch password cracking. This is the most technically demanding scenario. The approach: extract hashes from all PDFs, classify by encryption mode, and run hashcat on the batch.

Step 1: Use pdf2john.pl (John the Ripper's PDF hash extractor) to extract hash lines from all PDFs. Batch: for f in *.pdf; do pdf2john.pl "$f"; done > pdf_hashes.txt. The output is one hash line per file with the encryption parameters.

Step 2: Sort hashes by mode. Mode 10400 (40-bit RC4) should be separated from mode 10700 (AES-256) because different cracking strategies apply. Mode 10400 (V=1/R=2) is recoverable in practice for these old files, because the file key is only 40 bits; mode 10700 requires dictionary+rule attacks.

Step 3: Run hashcat in dictionary mode against the batch: hashcat -m 10700 pdf_hashes.txt wordlist.txt -r best66.rule. Hashcat processes all hashes simultaneously — one cracked hash per file means that file's password was found. Files not cracked after the dictionary phase proceed to mask attack.

Hashcat batch optimizations

When cracking multiple PDF hashes simultaneously, hashcat shares candidate generation and removes per-run overhead — but the cost scales with the number of distinct-salt files. Each PDF's hash carries its own salt (/O, /U, /P, /ID), so the key derivation is recomputed for every file for every candidate password: a batch of 1,000 mode 10700 hashes against a 10-million-word dictionary costs on the order of 1,000 times a single hash.

Use hashcat's --outfile-autohex-disable flag for clean plaintext output, and --show after the run to list all cracked passwords. The hashcat potfile automatically tracks per-hash status — re-running the same batch skips already-cracked hashes.

For mode 10400 (40-bit RC4) batch cracking, remember that hashcat tests candidate passwords: it derives the file key and decrypts the known padding in /U for each candidate, so a mask attack over short candidate passwords is the practical route — not enumeration of the 2^40 key space. (Recovering the RC4 key directly from the known padding is a real technique, but it needs separate tooling that hashcat does not implement.) Because the underlying key is only 40 bits, mask attacks against these old files are cheap.

Automation infrastructure recommendations

Local GPU cluster: 4-8 high-end GPUs (RTX 5090 or equivalent). Cost scales with the number of distinct-salt files, so testing 10,000-50,000 mode 10700 hashes against a 10M-word dictionary with 50 rules is a multi-day job for a small cluster — each file pays the revision-6 key derivation again for every candidate password.

Cloud GPU instances: AWS EC2 G6e (L40S GPU) or G6 (L4), Azure NC A100 v4, or Vast.ai rentals. Cloud GPUs are cost-effective for one-time batch cracking jobs — you stop the instance when done and pay only for compute time.

Job management: use hashcat's --potfile-disable for fully isolated per-run tracking, or --potfile-path to specify a custom potfile path per batch. For large batches, split the hash list into sub-batches (500-1,000 hashes each) and run on separate GPU instances to scale horizontally.

Handling mixed encryption tiers in a batch

Not all PDFs in a batch use the same encryption. A corporate archive spanning 2000-2026 likely contains: mode 10400 (PDF 1.1-1.3, pre-2001), mode 10500 (V=2/R=3 RC4-128 and V=4/R=4 AES-128), mode 10600 (PDF 1.7 extension level 3 / Acrobat 9, AES-256), and mode 10700 (PDF 1.7 extension level 8 / Acrobat 10-11, AES-256).

Extract all hashes with pdf2john.pl, which tags each line with the filename and encryption parameters. Then filter on the hash prefix — the fields are version*revision*keylength, so grep '$pdf$1*2*40' selects mode 10400, '$pdf$2*3*128' mode 10500, '$pdf$5*5*256' mode 10600 and '$pdf$5*6*256' mode 10700 — and crack each mode group separately with appropriate strategies.

Mode 10400: mask attack over candidate passwords (the small 40-bit key makes this cheap). Modes 10500-10600: dictionary+rule attack (human-chosen passwords are likely). Mode 10700: dictionary+rule first, then mask attack with character-class constraints if no success.

Batch output verification and quality control

After batch cracking: run qpdf --decrypt with the found password to verify the output opens correctly. Use a script to check exit codes and file sizes. Unsuccessfully decrypted files (wrong password, no password found) should be quarantined for separate handling.

For files where hashcat found a password but qpdf rejects it: verify the hash extraction was correct (re-run pdf2john.pl and hashcat --show). Some PDFs are corrupted badly enough to prevent proper decryption even with the correct password — a PDF has a single /Encrypt dictionary, so a rejection means a bad extraction or a damaged file, not an extra layer to peel.

Document the batch process thoroughly — especially which mode groups failed and why. For a corporate migration the pattern is qualitative rather than percentage-based: files whose passwords were human-chosen usually fall to dictionary and rule attacks within the batch window, while files protected by long random passwords generally do not fall at all, on any encryption tier.

Batch PDF unlock flow

  1. 1

    Inventory the batch

    Count files, check encryption tiers with qpdf --show-encryption, estimate total processing time.

  2. 2

    Extract all hashes

    pdf2john.pl *.pdf > pdf_hashes.txt. One hash line per file, tagged by mode.

  3. 3

    Sort by encryption mode

    Separate mode 10400 (V=1/R=2 40-bit files, cheap to search) from 10500-10700 (password search over modern KDFs).

  4. 4

    Crack each mode group

    Mode 10400: mask attack over short candidate passwords. Modes 10500-10700: dictionary+rule attack on a multi-GPU cluster.

  5. 5

    Verify and decrypt

    Use hashcat --show to extract found passwords, then qpdf --decrypt each file with its password. Log failures for manual review.

Frequently Asked Questions

What is the fastest tool for batch PDF decryption?
QPDF with GNU parallel for known-password batches. Hashcat for unknown-password batches. Both are free and open-source.
Can I batch-crack PDFs on a CPU instead of GPU?
Yes, with John the Ripper (JtR). For modes 10500-10700, CPU throughput is one to two orders of magnitude lower than a GPU's, and worst for mode 10700, whose iterated key derivation dominates. Mode 10400 is fast enough on CPU for small batches.
What about PDFs with different passwords per file?
Hashcat tracks per-hash status in its potfile automatically — use --potfile-path for a custom location, or --potfile-disable to suppress it. It tests each candidate password against all hashes in the batch, handling per-file passwords efficiently.
How do I handle PDF 2.0 files in a batch?
PDF 2.0 encryption uses the same revision 6 scheme (mode 10700) as PDF 1.7 extension level 8, so no special handling is needed. pdf2john and current hashcat (6.x/7.x) handle them.
What if some PDFs in the batch are corrupted?
QPDF reports errors for corrupted files. Separate corrupted files from the batch and repair first (see PDF repair guides). Cracking a corrupted file's password is useless if the decrypt dictionary is unreadable.
Are there commercial batch PDF unlock tools?
Yes: Passware Kit Forensic, Elcomsoft Advanced PDF Password Recovery, and Recovery Toolbox for PDF Password offer batch processing with a GUI. They automate the full pipeline, though licensing differs sharply between a consumer unlocker and a forensic suite.

Have a forgotten-password PDF to recover?

Run a free analysis — encryption type detected automatically, fast techniques tried first, pay only on success.

Run Free Analysis

Related Reading