Last active
December 31, 2023 22:48
-
-
Save xzer/9d89e28d40372c3ce2b222ccdf386351 to your computer and use it in GitHub Desktop.
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
brew install ghostscript | |
# predefined ebook compression | |
``` | |
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="output.pdf" input.pdf | |
``` | |
compress with resolution: | |
144 can be replaced to 288 or further, but since 144 is slightly worse than above default, and 288 has good quality but may still too big in some situations | |
``` | |
gs \ | |
-q -dNOPAUSE -dBATCH -dSAFER \ | |
-sDEVICE=pdfwrite \ | |
-dCompatibilityLevel=1.3 \ | |
-dPDFSETTINGS=/screen \ | |
-dEmbedAllFonts=true -dSubsetFonts=true \ | |
-dColorImageDownsampleType=/Bicubic \ | |
-dColorImageResolution=144 \ | |
-dGrayImageDownsampleType=/Bicubic \ | |
-dGrayImageResolution=144 \ | |
-dMonoImageDownsampleType=/Bicubic \ | |
-dMonoImageResolution=144 \ | |
-sOutputFile=output.pdf \ | |
input.pdf | |
``` | |
simpler sh function: | |
``` | |
pdfcompress() { | |
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$1.compressed.pdf" $1 | |
} | |
# merge pdf | |
cpdf () { | |
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$1" "${@:2}" | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment