summaryrefslogtreecommitdiff
path: root/localpdf2ps2pdf
diff options
context:
space:
mode:
Diffstat (limited to 'localpdf2ps2pdf')
-rwxr-xr-xlocalpdf2ps2pdf95
1 files changed, 95 insertions, 0 deletions
diff --git a/localpdf2ps2pdf b/localpdf2ps2pdf
new file mode 100755
index 0000000..7fe0a17
--- /dev/null
+++ b/localpdf2ps2pdf
@@ -0,0 +1,95 @@
+#!/bin/sh
+#
+# /usr/local/bin/localpdf2ps2pdf
+# Copyright 2008-2023 Jonas Smedegaard <dr@jones.dk>
+#
+# Refry PDF file.
+#
+
+set -e
+
+PRG="$(basename "$0")"
+
+# Default options
+PDF2PSOPTS=""
+PS2PDFOPTS="-dDownsampleColorImages=true -dColorImageResolution=150"
+
+showhelp() {
+ cat <<EOF
+Usage: $PRG INFILE [ OUTFILE ] [ pdf2ps opts ] [ -- ps2pdf opts ]
+
+Defaults:
+ OUTFILE: INFILE with trailing ".pdf" replaced with "_lowres.pdf".
+ pdf2ps: $pdf2psOPTS
+ ps2pdf: $PS2PDFOPTS
+
+Examples:
+ $PRG file.pdf dFirstPage=7 -dLastPage=9
+ $PRG file.pdf -- -dPDFA -dPDFACompatibilityPolicy=1
+ $PRG file.pdf -- -dPDFSETTINGS=/screen
+ $PRG file.pdf -dLanguageLevel=3 -- -dPDFSETTINGS=/prepress
+
+First example above picks pages 7-9.
+Second example above reduces PDF complexity.
+Third example reduces image size for screen-only use.
+Fourth example preserves complexity and image size for professional use.
+
+Defaults reduce file size for 300 DPI color print use.
+
+EOF
+}
+
+exit1() {
+ echo >&2 "ERROR: $1"
+ exit 1
+}
+
+[ $# -gt 0 ] || exit1 "Input file missing"
+
+infile=
+outfile=
+pdf2psopts=
+pstopdfopts=
+while [ $# -gt 0 ]; do
+ case $1 in
+ -h|--help)
+ showhelp
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ pdf2psopts="$pdf2psopts $1"
+ shift
+ ;;
+ *)
+ if [ -z "$infile" ]; then
+ infile="$1"
+ elif [ -z "$outfile" ]; then
+ outfile="$1"
+ else
+ exit1 "Too many parameters"
+ fi
+ shift
+ ;;
+ esac
+done
+ps2pdfopts="$@"
+
+# Use defaults if not overridden
+outfile="${outfile:-$(basename "$infile" .pdf)_lowres.pdf}"
+pdf2psopts="${pdf2psopts:-$PDF2PSOPTS}"
+ps2pdfopts="${ps2pdfopts:-$PS2PDFOPTS}"
+
+[ ! -e "$outfile" ] || exit1 "Output file already exists"
+
+tmpfile=$(mktemp -t "$PRG.XXXXXXXXXX") || exit 1
+
+pdf2ps $pdf2psopts "$infile" "$tmpfile" || rm "$tmpfile"
+ps2pdf $ps2pdfopts "$tmpfile" "$outfile"
+
+rm "$tmpfile"
+
+exit 0