xref: /plan9/rc/bin/ps2pdf (revision d2fd7a449ba15afc3f4999c6b00b9a2264c19913)
1#!/bin/rc
2# ps2pdf - convert PostScript to PDF
3rfork e
4
5fn usage {
6	echo 'usage: ps2pdf [gs-options] [input.ps [output.pdf]]' >[1=2]
7	exit usage
8}
9
10# gs's pdfwrite sometimes emits bad pdf at level 1.2,
11# but 1.4 seems to work fine.
12compat=(-'dCompatibilityLevel=1.2')
13opt=()
14while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
15	if(~ $1 '-dCompatibilityLevel='*)
16		compat=()
17	opt=($opt $1)
18	shift
19}
20if(~ $1 --)
21	shift
22
23switch($#*){
24case 0
25	fin='-'
26	fout='-'
27case 1
28	fin=$1
29	fout='-'
30case 2
31	fin=$1
32	fout=$2
33case *
34	usage
35}
36
37# We have to include the options twice because -I only takes effect
38# if it appears before other options.
39
40gscmd=( gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pdfwrite' \
41	$opt $compat \
42	-s'OutputFile='$fout -c .setpdfwrite -f $fin)
43exec $gscmd
44