pdfgs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/rc
  2. # pdfgs pdffile [gsdev] - generate PS from PDF
  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. switch($#*) {
  8. case 2
  9. GSDEVICE=$2
  10. case 1
  11. GSDEVICE=`{echo $LPCLASS | sed 's/(.*\+)?gs!([^+]*)(\+.*)?/\2/'}
  12. case *
  13. echo 'usage: pdfgs pdffile [gsdev]' >[1=2]
  14. exit usage
  15. }
  16. GSTMPFILE=/tmp/pdf^$pid
  17. GSOPT=('-sDEVICE='$GSDEVICE '-sOutputFile='^$GSTMPFILE -dSAFER -dNOPAUSE \
  18. -dQUIET -dBATCH -dNOPAUSE)
  19. # ps level 1 is extremely verbose and tends to run our
  20. # printers out of memory when printing images.
  21. if(~ $GSDEVICE pswrite && ~ $LPCLASS *post2*)
  22. GSOPT=($GSOPT '-dLanguageLevel=2')
  23. if not if(~ $GSDEVICE pswrite)
  24. GSOPT=($GSOPT '-dLanguageLevel=1')
  25. if(~ $OLIST '')
  26. gs $GSOPT $1
  27. if not {
  28. PGLIST=`{echo $OLIST | sed 's/-o//;s/,/ /g;s/ / /g' | tr -cd '0-9 -'}
  29. GSPGLIST=()
  30. for(i in $PGLIST){
  31. switch($i){
  32. case -*
  33. GSPGLIST=($GSPGLIST `{seq 1 `{echo $i|tr -d '-'}})
  34. case *-
  35. # BUG assume 100 >= number of pages
  36. GSPGLIST=($GSPGLIST `{seq `{echo $i|tr -d '-'} 100})
  37. case *-*
  38. GSPGLIST=($GSPGLIST `{seq `{echo $i|tr '-' ' '}})
  39. case *
  40. GSPGLIST=($GSPGLIST $i)
  41. }
  42. }
  43. GSPGLIST=$"GSPGLIST
  44. echo '
  45. /Page null def
  46. /Page# 0 def
  47. /PDFSave null def
  48. /DSCPageCount 0 def
  49. /DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage} def
  50. GS_PDF_ProcSet begin
  51. pdfdict begin
  52. ('^$1^') (r) file pdfopen begin
  53. /npage pdfpagecount def
  54. ['^$GSPGLIST^']
  55. {
  56. dup dup
  57. 1 ge exch npage le and
  58. { DoPDFPage }
  59. { pop }
  60. ifelse
  61. } forall
  62. ' | gs $GSOPT - >/dev/null >[2=1]
  63. }
  64. cat $GSTMPFILE
  65. rm -f $GSTMPFILE
  66. exit ''