-
Notifications
You must be signed in to change notification settings - Fork 3
/
pdf2eps
executable file
·59 lines (48 loc) · 1.31 KB
/
pdf2eps
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
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# choose which to progs to try:
inkscape=true
gs=true
imagemagick=true
pdftops=true
conversion (){
# get file name without extension, full path
b="${1%%.*}"
b=`basename $b`
full=`grealpath $1`
echo "Converting: $1 (Absolute path: $full)"
dir="`dirname $full`/converted"
mkdir -p $dir
### Inkscape
if [ $inkscape = true ]; then
inkscape $full --export-eps=${dir}/${b}_inkscape.eps
if [ $? -ne 0 ]; then echo "Inkscape failed" && inkscape=false; fi
fi
### ImageMagick
if [ $imagemagick = true ]; then
convert $full ${dir}/${b}_imagemagick.eps
if [ $? -ne 0 ]; then echo "ImageMagick failed" && imagemagick=false; fi
fi
### ghostscript
if [ $gs = true ]; then
gs -q -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=eps2write -sOutputFile=${dir}/${b}_gs.eps $full
if [ $? -ne 0 ]; then echo "Ghostscript failed" && gs=false; fi
fi
### pdftops
if [ $pdftops = true ]; then
pdftops -eps $full
mv "`dirname $full`/$b.eps" ${dir}/${b}_pdftops.eps 2>/dev/null
if [ $? -ne 0 ]; then echo "pdftops failed" && pdftops=false; fi
fi
}
if [[ -f $1 ]]; then
# if a single file
conversion $1
# elif [[ -d $1 ]]; then
# # else if a directory
# for i in `ls $1/*.pdf`; do
# conversion $i
# done
else
echo "Call: ./pdf2eps [PDF file]"
exit 1
fi