Skip to content

Instantly share code, notes, and snippets.

@angrykoala
Created February 13, 2019 10:37
Show Gist options
  • Save angrykoala/d9033c5daa643f7528592d4fa49bcb70 to your computer and use it in GitHub Desktop.
Save angrykoala/d9033c5daa643f7528592d4fa49bcb70 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Unites and compress pdf
# Usage compress_pdf.sh file1.pdf file2.pdf output_file.pdf
last_arg=${*: -1:1}
last_arg_temp="${last_arg}_temp.pdf"
args_except_last=${@:1:$#-1}
echo "Creating pdf $last_arg"
pdfunite "$@"
echo "Compressing pdf $last_arg using ps"
pdf2ps "${last_arg}" "${last_arg}.ps"
ps2pdf "${last_arg}.ps" "${last_arg}"
rm "${last_arg}.ps"
#echo "Compressing pdf $last_arg with gs" -- todo: make this and options, lossy compression
#gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$last_arg_temp" "$last_arg"
#rm "$last_arg"
#mv "$last_arg_temp" "$last_arg"
echo "Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment