Created
September 11, 2022 23:07
-
-
Save bng44270/d6ac5e86da144dc0c99d82fa0320fc2c to your computer and use it in GitHub Desktop.
Resample resolution of images in PDF file (requires Ghostscript)
This file contains hidden or 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 | |
############################# | |
# | |
# Resample image content in PDF | |
# | |
# Usage: | |
# | |
# resample_pdf.sh -i <input file> -r <resample_resolution> -o <output_file> | |
# | |
############################# | |
getargs() { | |
echo "$@" | sed 's/[ \t]*\(-[a-zA-Z][ \t]\+\)/\n\1/g' | awk '/^-/ { printf("ARG_%s=\"%s\"\n",gensub(/^-([a-zA-Z]).*$/,"\\1","g",$0),gensub(/^-[a-zA-Z][ \t]+(.*)[ \t]*$/,"\\1","g",$0)) }' | sed 's/""/"EMPTY"/g' | |
} | |
eval $(getargs "$@") | |
if [ -z "$ARG_i" ] && [ -z "$ARG_o" ] && [ -z "$ARG_r" ]; then | |
echo "usage: resample-pdf.sh -i <input_file> -r <resample_resolution> -o <output_file>" | |
else | |
gs \ | |
-o $ARG_o \ | |
-sDEVICE=pdfwrite \ | |
-dPDFSETTINGS=/prepress \ | |
`# font settings` \ | |
-dSubsetFonts=true \ | |
-dCompressFonts=true \ | |
`# color format` \ | |
-sProcessColorModel=DeviceRGB \ | |
-sColorConversionStrategy=sRGB \ | |
-sColorConversionStrategyForImages=sRGB \ | |
-dConvertCMYKImagesToRGB=true \ | |
`# image resample` \ | |
-dDetectDuplicateImages=true \ | |
-dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true \ | |
-dColorImageResolution=$ARG_r -dGrayImageResolution=$ARG_r -dMonoImageResolution=$ARG_r \ | |
`# preset overrides` \ | |
-dDoThumbnails=false \ | |
-dCreateJobTicket=false \ | |
-dPreserveEPSInfo=false \ | |
-dPreserveOPIComments=false \ | |
-dPreserveOverprintSettings=false \ | |
-dUCRandBGInfo=/Remove \ | |
-f $ARG_i | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment