-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpdfselect.sh
46 lines (39 loc) · 1.08 KB
/
pdfselect.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
# file: pdfselect.sh
# vim:fileencoding=utf-8:ft=sh
#
# Copyright © 2015-2016 R.F. Smith <[email protected]>.
# SPDX-License-Identifier: MIT
# Created: 2015-05-08T22:12:45+02:00
# Last modified: 2024-02-16T20:01:14+0100
set -e
if [ $# -lt 3 ]; then
echo "Usage: $(basename $0) N M file"
echo "Where 'N' to 'M' are the numbers of the page you want to extract."
echo "'file' is the name of the file you want to extract from."
echo "The page will be written to a file pageN(-M).pdf."
exit 1
fi
# Check for special programs that are used in this script.
PROGS="gs"
for P in $PROGS; do
which $P >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "$(basename $0): The program \"$P\" cannot be found."
exit 1
fi
done
N=$1
M=$2
if [ ! -f $3 ]; then
echo "File "$3" does not exist.";
exit 1;
fi
if [ ${N} -eq ${M} ]; then
OUTNAME=page${N}.pdf
else
OUTNAME=page${N}-${M}.pdf
fi
gs -DNOPAUSE -sDEVICE=pdfwrite -dFirstPage=${N} -dLastPage=${M} \
-dCompatibilityLevel=1.5 \
-sOutputFile=$OUTNAME "$3" -c quit 2>/dev/null | tail -n 4