Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
Created November 8, 2011 00:46
Show Gist options
  • Save carlohamalainen/1346684 to your computer and use it in GitHub Desktop.
Save carlohamalainen/1346684 to your computer and use it in GitHub Desktop.
Shrink a PDF file by transferring to DJVU, then PS, then back to PDF.
#!/bin/bash
set -o nounset # explode on undefined variables
set -e # explode if any command fails
# Best way to shrink a PDF of scanned pages without losing quality. Found on
# http://ubuntuforums.org/archive/index.php/t-1133357.html
# example: ./shrink_pdf.sh big_file.pdf 600 small_file.pdf
in_file=$1
resolution=$2
out_file=$3
temp_file1=`mktemp`
temp_file2=`mktemp`
pdf2djvu -d $resolution $in_file -o $temp_file1
djvups $temp_file1 $temp_file2
ps2pdf $temp_file2 $out_file
rm -f $temp_file1 $temp_file2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment