xref: /plan9/sys/lib/lp/process/pdfgsijs (revision 956c0eaf3abf2dda83b992e8647e26e606481e18)
1*956c0eafSDavid du Colombier#!/bin/rc
2*956c0eafSDavid du Colombier
3*956c0eafSDavid du Colombier# usage: pdfgsijs pdffile
4*956c0eafSDavid du Colombier
5*956c0eafSDavid du Colombiergs -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pswrite' -d'LanguageLevel=2' -s'OutputFile=/tmp/pdf2ps.ps' $1
6*956c0eafSDavid du Colombier
7*956c0eafSDavid du ColombierMODEL=`{echo $LPCLASS | sed 's/(.*\+)?gsijs!([^+]*)(\+.*)?/\2/'}
8*956c0eafSDavid du ColombierNUMBER=`{echo $LPCLASS | sed 's/(.*\+)?gsijs!([^+]*)\+(.*)?/\3/'}
9*956c0eafSDavid du Colombier
10*956c0eafSDavid du ColombierGSTMPFILE=/tmp/pdf^$pid
11*956c0eafSDavid du Colombier
12*956c0eafSDavid du Colombierswitch($NUMBER) {
13*956c0eafSDavid du Colombiercase 2100
14*956c0eafSDavid du Colombier	GSOPT=(-q -sDEVICE'='ijs -sIjsServer'='hpijs -sDeviceManufacturer'='HP '-sDeviceModel='"$MODEL^' '^$NUMBER" -r600 -sOutputFile'='^$GSTMPFILE  -sPAPERSIZE'='a4 -dIjsUseOutputFD -dSAFER -dNOPAUSE -dBATCH)
15*956c0eafSDavid du Colombiercase 2500
16*956c0eafSDavid du Colombier	GSOPT=(-q -sDEVICE'='ijs -sIjsServer'='hpijs -sDeviceManufacturer'='HP '-sDeviceModel='"$MODEL^' '^$NUMBER" -r600 -sOutputFile'='^$GSTMPFILE -dDuplex'='true -sPAPERSIZE'='a4 -dIjsUseOutputFD -dSAFER -dNOPAUSE -DBATCH)
17*956c0eafSDavid du Colombier}
18*956c0eafSDavid du Colombier
19*956c0eafSDavid du Colombier
20*956c0eafSDavid du Colombierif(~ $OLIST '')
21*956c0eafSDavid du Colombier	gs $GSOPT /tmp/pdf2ps.ps
22*956c0eafSDavid du Colombierif not {
23*956c0eafSDavid du Colombier	PGLIST=`{echo $OLIST | sed 's/-o//;s/,/ /g;s/	/ /g' | tr -cd '0-9 -'}
24*956c0eafSDavid du Colombier	GSPGLIST=()
25*956c0eafSDavid du Colombier	for(i in $PGLIST){
26*956c0eafSDavid du Colombier		switch($i){
27*956c0eafSDavid du Colombier		case -*
28*956c0eafSDavid du Colombier			GSPGLIST=($GSPGLIST `{seq 1 `{echo $i|tr -d '-'}})
29*956c0eafSDavid du Colombier		case *-
30*956c0eafSDavid du Colombier			# BUG assume 100 >= number of pages
31*956c0eafSDavid du Colombier			GSPGLIST=($GSPGLIST `{seq `{echo $i|tr -d '-'} 100})
32*956c0eafSDavid du Colombier		case *-*
33*956c0eafSDavid du Colombier			GSPGLIST=($GSPGLIST `{seq `{echo $i|tr '-' ' '}})
34*956c0eafSDavid du Colombier		case *
35*956c0eafSDavid du Colombier			GSPGLIST=($GSPGLIST $i)
36*956c0eafSDavid du Colombier		}
37*956c0eafSDavid du Colombier	}
38*956c0eafSDavid du Colombier	GSPGLIST=$"GSPGLIST
39*956c0eafSDavid du Colombier	echo '
40*956c0eafSDavid du Colombier		/Page null def
41*956c0eafSDavid du Colombier		/Page# 0 def
42*956c0eafSDavid du Colombier		/PDFSave null def
43*956c0eafSDavid du Colombier		/DSCPageCount 0 def
44*956c0eafSDavid du Colombier		/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage} def
45*956c0eafSDavid du Colombier		GS_PDF_ProcSet begin
46*956c0eafSDavid du Colombier		pdfdict begin
47*956c0eafSDavid du Colombier		('^$1^') (r) file pdfopen begin
48*956c0eafSDavid du Colombier		/npage pdfpagecount def
49*956c0eafSDavid du Colombier		['^$GSPGLIST^']
50*956c0eafSDavid du Colombier		{
51*956c0eafSDavid du Colombier			dup dup
52*956c0eafSDavid du Colombier				1 ge exch npage le and
53*956c0eafSDavid du Colombier				{ DoPDFPage }
54*956c0eafSDavid du Colombier				{ pop }
55*956c0eafSDavid du Colombier			ifelse
56*956c0eafSDavid du Colombier		} forall
57*956c0eafSDavid du Colombier	' | gs $GSOPT - >/dev/null >[2=1]
58*956c0eafSDavid du Colombier}
59*956c0eafSDavid du Colombier
60*956c0eafSDavid du Colombiercat $GSTMPFILE
61*956c0eafSDavid du Colombierrm -f $GSTMPFILE
62*956c0eafSDavid du Colombierrm -f /tmp/pdf2ps.ps
63*956c0eafSDavid du Colombierexit ''
64