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