summaryrefslogtreecommitdiff
path: root/rc/bin/pdf2ps
blob: 9dfc200bbc5875014d1226bbfab3f737e06387a1 (plain)
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
#!/bin/rc
# pdf2ps [gs-options] [input.pdf] [output.ps] - generate PS from PDF
rfork e

fn cleanup { }
fn usage {
	echo 'usage: pdf2ps [gs-options] [input.pdf] [output.ps]' >[1=2]
	exit usage
}

lang=(-'dLanguageLevel=2')
opt=()
while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
	if(~ $1 '-dLanguageLevel='*)
		lang=()
	opt=($opt $1)
	shift
}
if(~ $1 --)
	shift

switch($#*){
case 0
	fin=-
	fout=-
case 1
	fin=$1
	fout=-
case 2
	fin=$1
	fout=$2
case *
	usage
}

if(~ $fin -){
	# fin=/tmp/pdf2ps.$pid.^`{date -n}
	# fn cleanup { rm -f $fin }
	# cat >$tmp
	fin=/fd/0
}
if(~ $fout -)
	fout=/fd/1

# Doing an inital `save' helps keep fonts from being flushed between
# pages.  We have to include the options twice because -I only takes
# effect if it appears before other options.

gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pswrite' \
	$opt $lang \
	-s'OutputFile='$fout -c save pop -f $fin

cleanup