Skip to content

Instantly share code, notes, and snippets.

@AndreiBarsan
Created August 23, 2017 08:39
Show Gist options
  • Save AndreiBarsan/f7672c9d47005c0483b4b71558a9a51b to your computer and use it in GitHub Desktop.
Save AndreiBarsan/f7672c9d47005c0483b4b71558a9a51b to your computer and use it in GitHub Desktop.
Shrinks the PDF passsed to it
#!/usr/bin/env bash
# Heavily based on: https://softwarerecs.stackexchange.com/questions/18442/command-line-pdf-image-compression-optimizer, but less aggressive.
gs \
-o smaller-downsampled.pdf \
-sDEVICE=pdfwrite \
-dCompressPages=true \
-dCompressFonts=true \
-dDownsampleColorImages=true \
-dDownsampleGrayImages=true \
-dDownsampleMonoImages=true \
-dColorImageResolution=300 \
-dGrayImageResolution=300 \
-dMonoImageResolution=300 \
-dColorImageDownsampleThreshold=1.0 \
-dGrayImageDownsampleThreshold=1.0 \
-dMonoImageDownsampleThreshold=1.0 \
-dCompatibilityLevel=1.4 \
-c ".setpdfwrite <</AlwaysEmbed [ ] /NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats] /ColorImageFilter /DCTEncode /GrayImageFilter /DCTEncode /MonoImageFilter /CCITTFaxEncode /OutputICCProfile (None)>> setdistillerparams" \
-f "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment