-
Notifications
You must be signed in to change notification settings - Fork 11
/
fixbb.sh
40 lines (33 loc) · 911 Bytes
/
fixbb.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
#!/bin/sh
# file: fixbb.sh
# vim:fileencoding=utf-8:ft=sh
#
# Copyright © 2018 R.F. Smith <rsmith@xs4all.nl>.
# SPDX-License-Identifier: MIT
# Created: 2015-05-08T22:12:45+02:00
# Last modified: 2021-02-28T20:46:06+0100
set -e
# Check for arguments
if [ $# -eq 0 ]; then
echo "Usage: $(basename $0) filename"
exit 1
fi
if [ ! -f "$1" ]; then
echo "File "$1" doesn't exist!"
exit 0
fi
# Check for special programs that are used in this script.
P=gs
which $P >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "$(basename $0): The program \"$P\" cannot be found."
exit 1
fi
if ! grep '%%Pages\?:.*1' >/dev/null $1; then
echo "Sorry, this script only works for single-page documents!"
exit 0
fi
# Determine the new BoundingBox.
# This only works properly for single-page documents!
NEWBB=$(echo|gs -sDEVICE=bbox $1 -c quit 2>&1|grep '^%%B')
sed -I .bak -e "s/^%%Bound.*/$NEWBB/" $1