-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdfcropper
executable file
·48 lines (42 loc) · 1.05 KB
/
pdfcropper
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
47
48
#!/usr/bin/env bash
#
# NAME
#
# pdfcropper - run krop on a page range
#
# SYNOPSIS
#
# pdfcropper <file>
#
# DESCRIPTION
#
# pdfcropper extracts a range of pages from the supplied PDF using
# pdfjam and gives it to krop -- a simple graphical tool to crop PDF
# pages. Although krop has the functionality to krop a range of
# pages, it is slower on large PDFs, ergo this script.
#
# DEPENDENCIES
#
# krop(1), zenity(1), and pdfjam(1)
#
# SEE ALSO
#
# krop <http://arminstraub.com/software/krop>
#
[[ "$*" ]] || {
echo >&2 "usage: ${0##*/} <file>"
exit 1
}
pdf="$(mktemp -t XXXXXX.pdf)"
trap 'rm -rf "$pdf" >/dev/null 2>&1' EXIT
trap 'exit 2' HUP INT QUIT TERM
pages=$(zenity --entry --title="PDF Cropper" --text="Enter page range")
[[ "$pages" =~ [0-9,-]+ ]] || {
echo >&2 "${0##*/}: error extracting pages"
exit 1
}
# We could've used pdftk, but pdfjam is faster for extracting pages.
echo >&2 "${0##*/}: extracting page(s)"
pdfjam "$1" "$pages" -o "$pdf"
echo >&2 "${0##*/}: running krop"
exec krop "$pdf" -o "${1%.*}-cropped.pdf"