myps2pdf 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/sh -
  2. do_opt=1
  3. best=0
  4. rot=0
  5. a4=0
  6. eps=0
  7. usage="Usage: $0 [-no_opt] [-best] [-rot] [-a4] [-eps] in.ps [out.pdf]"
  8. case "x$1" in
  9. "x-no_opt") do_opt=0 ; shift ;;
  10. esac
  11. case "x$1" in
  12. "x-best") best=1 ; shift ;;
  13. esac
  14. case "x$1" in
  15. "x-rot") rot=1 ; shift ;;
  16. esac
  17. case "x$1" in
  18. "x-a4") a4=1 ; shift ;;
  19. esac
  20. case "x$1" in
  21. "x-eps") eps=1 ; shift ;;
  22. esac
  23. case $# in
  24. 2) ifilename=$1 ; ofilename=$2 ;;
  25. 1) ifilename=$1
  26. if `echo $1 | grep -i '\.e*ps$' > /dev/null`
  27. then
  28. ofilename=`echo $1 | sed 's/\..*$/.pdf/'`
  29. else
  30. echo "$usage" 1>&2
  31. exit 1
  32. fi ;;
  33. *) echo "$usage" 1>&2 ; exit 1 ;;
  34. esac
  35. if [ $best == 1 ]
  36. then
  37. options="-dPDFSETTINGS=/prepress \
  38. -r1200 \
  39. -dMonoImageResolution=1200 \
  40. -dGrayImageResolution=1200 \
  41. -dColorImageResolution=1200 \
  42. -dDownsampleMonoImages=false \
  43. -dDownsampleGrayImages=false \
  44. -dDownsampleColorImages=false \
  45. -dAutoFilterMonoImages=false \
  46. -dAutoFilterGrayImages=false \
  47. -dAutoFilterColorImages=false \
  48. -dMonoImageFilter=/FlateEncode \
  49. -dGrayImageFilter=/FlateEncode \
  50. -dColorImageFilter=/FlateEncode"
  51. else
  52. options="-dPDFSETTINGS=/prepress \
  53. -r600 \
  54. -dDownsampleMonoImages=true \
  55. -dDownsampleGrayImages=true \
  56. -dDownsampleColorImages=true \
  57. -dMonoImageDownsampleThreshold=2.0 \
  58. -dGrayImageDownsampleThreshold=1.5 \
  59. -dColorImageDownsampleThreshold=1.5 \
  60. -dMonoImageResolution=600 \
  61. -dGrayImageResolution=600 \
  62. -dColorImageResolution=600 \
  63. -dAutoFilterMonoImages=false \
  64. -dMonoImageFilter=/FlateEncode \
  65. -dAutoFilterGrayImages=true \
  66. -dAutoFilterColorImages=true"
  67. fi
  68. if [ $rot == 1 ]
  69. then
  70. options="$options -dAutoRotatePages=/PageByPage"
  71. fi
  72. if [ $eps == 1 ]
  73. then
  74. options="$options -dEPSCrop"
  75. fi
  76. set -x
  77. if [ $a4 == 1 ]
  78. then
  79. # Resize from A4 to letter size
  80. psresize -Pa4 -pletter "$ifilename" myps2pdf.temp.ps
  81. ifilename=myps2pdf.temp.ps
  82. fi
  83. gs -q -dSAFER -dNOPAUSE -dBATCH \
  84. -sDEVICE=pdfwrite -sPAPERSIZE=letter -sOutputFile=myps2pdf.temp.pdf \
  85. -dCompatibilityLevel=1.3 \
  86. $options \
  87. -dMaxSubsetPct=100 \
  88. -dSubsetFonts=true \
  89. -dEmbedAllFonts=true \
  90. -dColorConversionStrategy=/LeaveColorUnchanged \
  91. -dDoThumbnails=true \
  92. -dPreserveEPSInfo=true \
  93. -c .setpdfwrite -f "$ifilename"
  94. if [ $do_opt == 1 ]
  95. then
  96. pdfopt myps2pdf.temp.pdf $ofilename
  97. else
  98. mv myps2pdf.temp.pdf $ofilename
  99. fi
  100. rm -f myps2pdf.temp.pdf myps2pdf.temp.ps