1
0

pdfgs 1.7 KB

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