-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcroppdf.sh
executable file
·39 lines (33 loc) · 891 Bytes
/
croppdf.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
#!/bin/bash
#
# File to download, crop and open a pdf ready for printing in multipage.
# Intended to use for those book formated papers.
#
# Usage: ./croppdf.sh <URL of pdf>
# Example: ./croppdf.sh http://users.isr.ist.utl.pt/~rmcantin/papers/tesis.pdf
#
# Author: Ruben Martinez-Cantin <rmcantin@unizar.es>
#
# Remove version number
os=${OSTYPE//[0-9.]/}
if [ $# -ne 1 ]; then
echo "USAGE: You need to specify a URL or local path"
exit
fi
path="$1"
regex='(https?|ftp)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $path =~ $regex ]]
then
echo "Downloading file..."
wget $path -O temp_before_crop.pdf
else
echo "Using local file"
mv $path ./temp_before_crop.pdf
fi
pdfcrop temp_before_crop.pdf output.pdf
rm temp_before_crop.pdf
if [ "$os" = "darwin" ]; then
open output.pdf
elif [ "$os" = "linux-gnu" ]; then
xdg-open output.pdf
fi