pdftk: Compressing a bunch of PDFs en masse/in batch while keeping the filenames?

3

1

I have a rather simple problem. I have a lot of PDFs that I want to compress, all grouped by college class. I don't have the time or energy to manually run the compress command when I know I can automate the whole thing.

However, I don't want to change the names of the files; how can I use pdftk compress an entire folder's PDFs and place the compressed versions in another folder?

JesseTG

Posted 2012-08-27T00:40:56.473

Reputation: 311

Answers

5

in linux you can simply use these few lines of script:

#!/bin/bash
mkdir compressed
for f in *.pdf; do pdftk $f output compressed/$f compress; done
exit 0

Dingo

Posted 2012-08-27T00:40:56.473

Reputation: 834

This does not compress. Just moves the file. – wbad – 2019-01-06T19:00:00.127

Thanks! (Also, a quick Google tells me that for files with spaces, surround $f in quotes.) – JesseTG – 2012-08-31T17:32:12.937