gitweb rectification
[adesklets.git] / doc / gdesklets / ps2eps
blobc0b7636d4d0de25a288c4c16b215eb5d42c25a8c
1 #! /bin/sh
2 #------------------------------------------------------------------------------
3 # ps2eps, written by S.Fourmanoit, 2005
5 # Script that uses psutils and ghostscript to generate
6 # a sequence of compliant encapsulated postscript files
7 # out of a single postscript input.
9 # It was written as a filter for ansi2ps output, and its
10 # really not a generry usage converter.
12 # Typical usage:
14 # command_with_some_ansi_escaped_output | ansi2ps | ps2eps [prefix]
16 # Where prefix is the file prefix used for outputting.
18 # If nothing is specified, it is defaulted to /tmp/out
20 #------------------------------------------------------------------------------
21 # Capture input
23 IN=`mktemp`
24 cat > $IN
26 # Get the output prefix
28 PREFIX=$1
29 : ${PREFIX:=/tmp/out}
31 # Get the number of page
33 PAGES=$(sed -n '/^%%Pages: /{s/.*\([0-9]\+\)$/\1/;p}' $IN)
34 echo "Outputting $PAGES encapsulated postscripts."
36 for I in $(seq -w 1 $PAGES); do
37 FILE=${PREFIX}_${I}
38 echo -n "Extracting page ${I}..."
39 psselect -p${I} ${IN} ${FILE}.ps &> /dev/null
40 echo "OK"
41 echo -n "Computing bounding box..."
42 BBOX=$(gs -q -sDEVICE=bbox -dBATCH ${FILE}.ps 2>&1 | sed -n '/^%%/{1p}')
43 echo "OK."
44 echo -n "Finalizing eps creation..."
45 sed '/%%BoundingBox/{s/.*/'"${BBOX}"'/};s/showpage//g' ${FILE}.ps \
46 > ${FILE}.eps
47 rm ${FILE}.ps
48 echo "${FILE}.eps created."
49 done
51 # Final cleanup
52 rm $IN