xref: /plan9/rc/bin/pdf2ps (revision 9aeb76ce36a36ea3426f1a033ec905c77e766a95)
1#!/bin/rc
2# pdf2ps [-e] [gs-options] [input.pdf [output.ps]] - generate (e)ps from pdf
3rfork e
4
5fn usage {
6	echo 'usage: pdf2ps [-e] [gs-options] [input.pdf [output.ps]]' >[1=2]
7	exit usage
8}
9
10outdev=pswrite
11fin=/fd/0
12fout=/fd/1
13lang=(-'dLanguageLevel=2')
14opt=()
15while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
16	if(~ $1 '-dLanguageLevel='*)
17		lang=()
18	if not if(~ '-?' $1)
19		usage
20	if(~ $1 -e)
21		outdev=epswrite
22	if not
23		opt=($opt $1)
24	shift
25}
26if(~ $1 --)
27	shift
28
29switch($#*){
30case 0
31	;
32case 1
33	fin=$1
34case 2
35	fin=$1
36	fout=$2
37case *
38	usage
39}
40
41if(~ $fin -)
42	fin=/fd/0
43if(~ $fout -)
44	fout=/fd/1
45
46# Doing an inital `save' helps keep fonts from being flushed between
47# pages.  We have to include the options twice because -I only takes
48# effect if it appears before other options.
49
50exec gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE='$outdev $opt $lang \
51	-s'OutputFile=-' -c save pop -f $fin >$fout
52