How to Compress (More than one at a time) PDF files from terminal

I work with lots of rather large imaged documents ranging from a few bites to multiple gigs of data per file. I need these documents to take up less storage space and especially to be more electronically portable and transmittable.

For single documents, I’ve been using:

ps2pdf -dPDFSETTINGS=/ebook inputfile.pdf outputfile.pdf

Which code I found here on AskUbuntu, and it works great with individual files yielding around a 1 to 0.42 compression ratio resulting in an output file of less than half of the original size while maintaining an acceptable level of reading quality.

I want to now use this code for my pdf library of documents to convert ALL my previous pdf files using a single command from the terminal. My strategic objective is to avoid having to compress each individual pdf file individually; I want to type a line of code, hit enter, and then go do something else productive and come back and find this done, and I’m hoping to mogrify the files in place (as opposed to converting them, which would produce doubles of each file) in order to avoid having to delete the old files.

All these files are together in a single folder.

Any suggestions?

Thank you in advance!


You can use the same command or mogrify as you’ve said, just by adding a bit of bash.

find $HOME/PDF_Lib -iname '*.pdf' | while read pdf; do ps2pdf -dPDFSETTINGS=/ebook "$pdf" "${pdf:0:(-4)}_new.pdf"; done


find $HOME/PDF_Lib -iname '*.pdf' | while read pdf; do mogrify -resample 150 -compress JPEG -quality 80 "$pdf"; done

Source : Link , Question Author : Joshua Cummings , Answer Author : perdigueiro

Leave a Comment