some fixes

main
Antonio De Lucreziis 2 years ago
parent 5f496df275
commit 63a8436f11

@ -5,12 +5,11 @@ set -euo pipefail
help_message="$(cat <<END
usage: $(basename "$0") [OPTIONS...] INPUT_PDF OUTPUT_PDF
Converts a PDF file to a series of JPEG images using convert to reduce the quality
and then merges back the result in a single pdf
Converts a PDF file to a series of JPEG images to reduce the quality
and then merges them back in a single pdf.
Options:
-q, --quality Set the JPEG quality (default: 75)
-v, --verbose Enable verbose output, also shows an estimate of remaining time
-h, --help Display this help message
END
@ -22,7 +21,6 @@ function show_usage() {
}
quality=75
verbose=false
while [[ $# -gt 0 ]]
do
@ -34,10 +32,6 @@ do
shift # past argument
shift # past value
;;
-v|--verbose)
verbose=true
shift # past argument
;;
-h|--help)
show_usage
;;
@ -61,21 +55,19 @@ output_file="$2"
temp_pages_dir="$(mktemp -d)"
function logf {
if [ "$verbose" = true ]; then
printf "$@"
fi
}
logf "Rendering each page to a jpeg image (quality = $quality%)\n"
logf "Rendering each page to a jpeg image (quality = $quality)\n"
pdftoppm -r 300 -jpeg -jpegopt "quality=$quality,optimize=y" -progress $input_file "$temp_pages_dir/page"
for f in *.jpg; do
log "Wrapping $f into ${f/.jpg/.pdf}\n"
for f in "$temp_pages_dir"/page-*.jpg; do
logf "Wrapping $f into ${f/.jpg/.pdf}\n"
gs -dNOSAFER -sDEVICE=pdfwrite -o "${f/.jpg/.pdf}" /usr/share/ghostscript/lib/viewjpeg.ps -c "($f)" viewJPEG
done
logf "Merging compressed pages to a single PDF ()\n"
pdfunite "$temp_pages_dir"/page*.pdf $output_file
pdfunite "$temp_pages_dir"/page-*.pdf $output_file
rm -r "$temp_pages_dir"
logf "Done\n"

Loading…
Cancel
Save