pdfgs (1748B)
1 #!/usr/local/plan9/bin/rc 2 3 # 4 # we don't go through postscript, because to 5 # get to postscript, we send the pdf through gs! 6 # much easier to just go directly. 7 # 8 9 # usage: pdfgs pdffile [gsdev] 10 11 switch($#*) { 12 case 2 13 GSDEVICE=$2 14 case 1 15 GSDEVICE=`{echo $LPCLASS | sed 's/(.*\+)?gs!([^+]*)(\+.*)?/\2/'} 16 case * 17 echo 'usage: pdfgs pdffile [gsdev]' >[1=2] 18 } 19 20 GSTMPFILE=/tmp/pdf^$pid 21 GSOPT=('-sDEVICE='$GSDEVICE '-sOutputFile='^$GSTMPFILE -dSAFER -dNOPAUSE -dQUIET -dBATCH -dNOPAUSE) 22 23 # 24 # RSC: pswrite produces weird overbars on various 25 # letters, most notably Times-Roman A and h, unless 26 # we use LanguageLevel=1. This doesn't seem to be 27 # constrained to hp4simx printers, so just use LanguageLevel 1 28 # all the time. 29 # 30 31 #if(~ $dev pswrite && ~ $LPCLASS *hp4simx*) 32 # GSOPT=($GSOPT '-dLanguageLevel=1') 33 if(~ $GSDEVICE pswrite) 34 GSOPT=($GSOPT '-dLanguageLevel=1') 35 36 if(~ $OLIST '') 37 gs $GSOPT $1 38 if not { 39 PGLIST=`{echo $OLIST | sed 's/-o//;s/,/ /g;s/ / /g' | tr -cd '0-9 -'} 40 GSPGLIST=() 41 for(i in $PGLIST){ 42 switch($i){ 43 case -* 44 GSPGLIST=($GSPGLIST `{seq 1 `{echo $i|tr -d '-'}}) 45 case *- 46 # BUG assume 100 >= number of pages 47 GSPGLIST=($GSPGLIST `{seq `{echo $i|tr -d '-'} 100}) 48 case *-* 49 GSPGLIST=($GSPGLIST `{seq `{echo $i|tr '-' ' '}}) 50 case * 51 GSPGLIST=($GSPGLIST $i) 52 } 53 } 54 GSPGLIST=$"GSPGLIST 55 echo ' 56 /Page null def 57 /Page# 0 def 58 /PDFSave null def 59 /DSCPageCount 0 def 60 /DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage} def 61 GS_PDF_ProcSet begin 62 pdfdict begin 63 ('^$1^') (r) file pdfopen begin 64 /npage pdfpagecount def 65 ['^$GSPGLIST^'] 66 { 67 dup dup 68 1 ge exch npage le and 69 { DoPDFPage } 70 { pop } 71 ifelse 72 } forall 73 ' | gs $GSOPT - >/dev/null >[2=1] 74 } 75 76 cat $GSTMPFILE 77 rm -f $GSTMPFILE 78 exit ''