rtf2pdf.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # Convert an rtf document to pdf format using 'Ted' and 'GhostScript'.
  5. #
  6. # Usage rtf2pdf.sh --paper paper something.rtf something.pdf
  7. # Or rtf2pdf.sh something.rtf something.pdf
  8. #
  9. # Valid values for paper are a4, a5, a6, letter, legal and executive
  10. #
  11. # This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
  12. # 'Ted' documentation.
  13. #
  14. # If you want 'Ted' to use X11 configurable resources, use
  15. # Ted ++printToFilePaper ... In conjuction with X11 resources, the
  16. # standard X11 command line arguments to set resources can be practical. E.G:
  17. # Ted -xrm Ted.usePostScriptFilters:1 -xrm Ted.usePostScriptIndexedImages:1
  18. # ++printToFilePaper .....
  19. #
  20. # The file /usr/share/ghostscript/version/doc/Ps2pdf.htm documents
  21. # many settings for ghostscript that influence the generation of pdf.
  22. # The actual meaning of the parameters is explained in Adobe technical
  23. # note #5151: "Acobat Distiller Parameters". With some effort, note #5151
  24. # can be found using the search facility on www.adobe.com.
  25. #
  26. # To disable jpeg compression of 8 bit per component images:
  27. # -dAutoFilterColorImages=false -dEncodeColorImages=false
  28. # or
  29. # -dAutoFilterColorImages=false -sColorImageFilter=FlateEncode
  30. # to enable: (default)
  31. # -dAutoFilterColorImages=true
  32. #
  33. # To produce uncompressed pdf:
  34. # -dCompressPages=false
  35. # To produce compressed pdf: (default)
  36. # -dCompressPages=true
  37. #
  38. # Depending on your temper, you could also have a look at the pdfopt script
  39. #
  40. ########################################################################
  41. PAPER=
  42. case $# in
  43. 2)
  44. ;;
  45. 4)
  46. case $1 in
  47. --paper)
  48. ;;
  49. *)
  50. echo $0: '$1='$1 'Expected --paper'
  51. exit 1
  52. ;;
  53. esac
  54. case $2 in
  55. a4|a5|a6|letter|legal|executive)
  56. PAPER=$2
  57. ;;
  58. *)
  59. echo $0: '$2='$2 'Expected a4|a5|a6|letter|legal|executive'
  60. exit 1
  61. ;;
  62. esac
  63. shift; shift;
  64. ;;
  65. *)
  66. echo $0: '$#='$#
  67. exit 1
  68. ;;
  69. esac
  70. case $PAPER in
  71. ?*)
  72. Ted --printToFilePaper $1 /tmp/$$.ps $PAPER
  73. gs -q -dNOPAUSE \
  74. -sDEVICE=pdfwrite \
  75. -sPAPERSIZE=$PAPER \
  76. -sOutputFile=$2 \
  77. /tmp/$$.ps \
  78. -c quit
  79. rm /tmp/$$.ps
  80. ;;
  81. *)
  82. Ted --printToFile $1 /tmp/$$.ps
  83. gs -q -dNOPAUSE \
  84. -sDEVICE=pdfwrite \
  85. -sOutputFile=$2 \
  86. /tmp/$$.ps \
  87. -c quit
  88. rm /tmp/$$.ps
  89. ;;
  90. esac