-
Notifications
You must be signed in to change notification settings - Fork 2
/
cards.sh
executable file
·54 lines (42 loc) · 1.37 KB
/
cards.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
47
48
49
50
51
52
53
54
#!/bin/sh
export CLASSPATH='/usr/share/java/batik/xml-apis-ext.jar' #Arch bug
optipdf(){
unoptimized=$1
optimized=$2
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$optimized $unoptimized &>/dev/null
return $?
}
# Convert
#
xml=$1
xsl=$2
pdf=$3
cover=$4
tmppdf=`mktemp --suffix=.pdf`
tmppdf2=`mktemp --suffix=.pdf`
coverpdf=`mktemp --suffix=.pdf`
coverpdf2=`mktemp --suffix=.pdf`
tmpfo=`mktemp --suffix=.fo`
#echo "tmppdf=$tmppdf"
#echo "tmppdf2=$tmppdf2"
#echo "coverpdf=$coverpdf"
#echo "coverpdf2=$coverpdf2"
echo 'Running XSLTProc'
xsltproc --xinclude -o $tmpfo $xsl $xml &>/dev/null || { echo 'xsltproc failed'; exit 1; }
echo 'Running FOP'
fop -fo $tmpfo -pdf $tmppdf &>/dev/null || { echo 'fop failed'; exit 1; }
echo 'Running RST2PDF'
rst2pdf -o $coverpdf $cover &>/dev/null || { echo 'rst2pdf'; exit 1; }
#echo 'Running optipdf (1)'
#optipdf $coverpdf $coverpdf2 || { echo 'optipdf (1) failed'; exit 1; }
echo 'Running pdftk/stapler'
#rm $tmppdf2 #stapler doesn't like its files to exist
rm $tmppdf2 #stapler doesn't like its files to exist
stapler cat $coverpdf $tmppdf $tmppdf2 &>/dev/null || { echo 'stapler failed'; exit 1; }
#pdftk $coverpdf $tmppdf cat output $tmppdf2
echo 'Running optipdf (2)'
optipdf $tmppdf2 $pdf || { echo 'optipdf (2) failed'; exit 1; }
rm $tmppdf
rm $tmppdf2
rm $coverpdf
rm $tmpfo