Skip to content

Instantly share code, notes, and snippets.

@4383
Last active August 9, 2018 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4383/4a8f03a2425d0908d0ae073d58a07c56 to your computer and use it in GitHub Desktop.
Save 4383/4a8f03a2425d0908d0ae073d58a07c56 to your computer and use it in GitHub Desktop.
Bash functions to compress pdf files
## Bash functions to compress pdf files
## Usage:
## $ source compress-pdf.sh
## $ compress-pdf-medium
function compress-pdf-medium {
# Medium level compression
# Medium does mean it's the medium quality level
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook \
-dNOPAUSE \
-dBATCH \
-sOutputFile=$2 \
$1
}
function compress-pdf-low {
# Low level compression
# Low does mean it's the lowest quality level
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-dNOPAUSE \
-dBATCH \
-sOutputFile=$2 \
$1
}
function compress-pdf-high {
# High level compression
# High does mean it's the highest quality level
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-dNOPAUSE \
-dBATCH \
-sOutputFile=$2 \
$1
}
@4383
Copy link
Author

4383 commented Jul 17, 2018

Some bash functions for pdf files compression

Prerequisites

  • Ghostscript (PostScript and PDF language interpreter and previewer) apt-get install ghostscript

Usage

$ curl https://gist.github.com/4383/4a8f03a2425d0908d0ae073d58a07c56/raw/1f0b4a39d1fcca24b0b5f359929c6dd7cffbe0f4/compress-pdf.sh -o ~/.compress-pdf.sh
$ source ~/.compress-pdf.sh
$ compress-pdf-medium input.pdf output.pdf

Persistant configuration

You can source automaticaly these functions by adding the following command to your ~/.bashrc:

source ~/.compress-pdf.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment