Created
November 9, 2018 12:41
-
-
Save axltxl/86942452e16bc3ca7bbb6084d686c522 to your computer and use it in GitHub Desktop.
Downsample image-based PDF documents with Ghostscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: pdf_downsample.sh <input_pdf_file> <output_pdf_file> [output_dpi] | |
# A. J. Ricoveri (github.com/axltxl) | |
set -e | |
_pdf_help() { | |
echo "Usage: $0 <input_pdf_file> <output_pdf_file> [output_dpi]" | |
exit 1 | |
} | |
_pdf_downsample() { | |
local input_pdf_file=$1 | |
local output_pdf_file=$2 | |
local output_dpi=$3 | |
set -x | |
gs \ | |
-o $output_pdf_file \ | |
-sDEVICE=pdfwrite \ | |
-dDownsampleColorImages=true \ | |
-dDownsampleGrayImages=true \ | |
-dDownsampleMonoImages=true \ | |
-dColorImageResolution=$output_dpi \ | |
-dGrayImageResolution=$output_dpi \ | |
-dMonoImageResolution=$output_dpi \ | |
-dColorImageDownsampleThreshold=1.0 \ | |
-dGrayImageDownsampleThreshold=1.0 \ | |
-dMonoImageDownsampleThreshold=1.0 \ | |
$input_pdf_file | |
set +x | |
} | |
input_pdf_file=$1 | |
output_pdf_file=${2:-pdf_downsample.pdf} | |
output_dpi=${3:-300} | |
[ -z "$1" ] && _pdf_help | |
_pdf_downsample $input_pdf_file $output_pdf_file $output_dpi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment