ps2pdf 764 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/rc
  2. # ps2pdf - convert PostScript to PDF
  3. rfork e
  4. fn usage {
  5. echo 'usage: ps2pdf [gs-options] [input.ps [output.pdf]]' >[1=2]
  6. exit usage
  7. }
  8. # gs's pdfwrite sometimes emits bad pdf at level 1.2,
  9. # but 1.4 seems to work fine.
  10. compat=(-'dCompatibilityLevel=1.2')
  11. opt=()
  12. while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 - --){
  13. if(~ $1 '-dCompatibilityLevel='*)
  14. compat=()
  15. opt=($opt $1)
  16. shift
  17. }
  18. if(~ $1 --)
  19. shift
  20. switch($#*){
  21. case 0
  22. fin='-'
  23. fout='-'
  24. case 1
  25. fin=$1
  26. fout='-'
  27. case 2
  28. fin=$1
  29. fout=$2
  30. case *
  31. usage
  32. }
  33. # We have to include the options twice because -I only takes effect
  34. # if it appears before other options.
  35. gscmd=( gs $opt -dSAFER -dNOPAUSE -dBATCH -q -s'DEVICE=pdfwrite' \
  36. $opt $compat \
  37. -s'OutputFile='$fout -c .setpdfwrite -f $fin)
  38. exec $gscmd