#!/bin/bash # # Syntax: pdf_concat_gs [-h] [-o output_file] pdf_files # # Purpose: Use gs to concatenate pdf files. # Use the -o flag to specify the output file. # The -h flag shows the help info for this command. # Created: Jan 1, 2011 by Bart De Schutter # Last revised: Dec 30, 2012 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: pdf # # Define default options # output="" # # Process options # while getopts :ho: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; o) output="$OPTARG";; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi if [ -z "$output" ]; then echo >&2 echo >&2 "ERROR: The output file has to be specified (via the -o flag)." echo >&2 exit 1 fi gs -q -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \ -dPDFSETTINGS=/prepress \ -dCompatibilityLevel=1.4 \ -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100 \ -dAutoFilterColorImages=false -dAutoFilterGrayImages=false \ -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode \ -dAutoFilterMonoImages=false -dMonoImageFilter=/CCITTFaxEncode \ -sOutputFile="$output" \ "$@" # Extra option: -sPAPERSIZE=a4 # -dPDFSETTINGS=/prepress