-
-
Save ilovefreesw/7eab3ebcb6f4cd69cf275f9a21c7eb48 to your computer and use it in GitHub Desktop.
| from __future__ import print_function | |
| import os | |
| import subprocess | |
| root = "." | |
| try: | |
| os.mkdir('compressed') | |
| except FileExistsError: | |
| pass | |
| for file in os.listdir(root): | |
| if file.endswith(".pdf"): | |
| filename = os.path.join(root, file) | |
| arg1= '-sOutputFile=' + './compressed/' + file | |
| print ("compressing:", file ) | |
| p = subprocess.Popen(['gs', '-sDEVICE=pdfwrite', '-dCompatibilityLevel=1.4', '-dPDFSETTINGS=/screen', '-dNOPAUSE', '-dBATCH', '-dQUIET', str(arg1), filename], stdout=subprocess.PIPE).wait() |
General command: gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -dQUIET -sOutputFile=Output.pdf Input.pdf
gswin64 -q -dNOPAUSE -dBATCH -dSAFER -dOverPrint=/simulate -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=150 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=150 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=150 -sOutputFile="output.pdf" "input.pdf"
gswin64c -sDEVICE=pdfwrite -o output.pdf -dCompatibilityLevel='1.4' -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH input.pdf
On Linux or macOS, change gswin64c to just gs
With Image Compression: gs -q -dNOPAUSE -dBATCH -dSAFER -dOverPrint=/simulate -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dDownsampleColorImages=true -dColorImageResolution=72 -dGrayImageResolution=72 -dMonoImageResolution=72 -dCompressFonts=true -dCompatibilityLevel=1.4 -sOutputFile="output.pdf" Input .pdf
Complete tutorial here: https://www.ilovefreesoftware.com/02/tutorial/how-to-batch-compress-pdf-files-using-ghostscript.html