From dd2db3ad3dfdd3bb74775b87701c28e0b923da72 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Fri, 5 Jan 2024 03:28:36 +0100 Subject: rename localpdf2pdfscreen -> localpdf2ps2pdf, optimize for consumer print by default, and improve help output --- localpdf2ps2pdf | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 localpdf2ps2pdf (limited to 'localpdf2ps2pdf') diff --git a/localpdf2ps2pdf b/localpdf2ps2pdf new file mode 100755 index 0000000..686d000 --- /dev/null +++ b/localpdf2ps2pdf @@ -0,0 +1,95 @@ +#!/bin/sh +# +# /usr/local/bin/localpdf2ps2pdf +# Copyright 2008-2023 Jonas Smedegaard +# +# Refry PDF file. +# + +set -e + +PRG="$(basename "$0")" + +# Default options +PDFTOPSOPTS="-preload -paper match" +PS2PDFOPTS="-dDownsampleColorImages=true -dColorImageResolution=150" + +showhelp() { + cat <&2 "ERROR: $1" + exit 1 +} + +[ $# -gt 0 ] || exit1 "Input file missing" + +infile= +outfile= +pdftopsopts= +pstopdfopts= +while [ $# -gt 0 ]; do + case $1 in + -h|--help) + showhelp + exit 0 + ;; + --) + shift + break + ;; + -*) + pdftopsopts="$pdftopsopts $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}" +pdftopsopts="${pdftopsopts:-$PDFTOPSOPTS}" +ps2pdfopts="${ps2pdfopts:-$PS2PDFOPTS}" + +[ ! -e "$outfile" ] || exit1 "Output file already exists" + +tmpfile=$(mktemp -t "$PRG.XXXXXXXXXX") || exit 1 + +pdftops $pdftopsopts "$infile" "$tmpfile" || rm "$tmpfile" +ps2pdf $ps2pdfopts "$tmpfile" "$outfile" + +rm "$tmpfile" + +exit 0 -- cgit v1.2.3