Plan 9 from Bell Labs’s /usr/web/sources/contrib/someone/root/rc/bin/pdf2ps

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/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
}

if (~ $cputype riscv64) {		# see /*64/bin/page
	curdir=`{pwd}
	cpu -h $pccpu -c 'bindterm; cd '^$curdir^'; ps2pdf '^$"*
	exit ''
}

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

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.