"Fossies" - the Fresh Open Source Software Archive

Member "usr/share/Ted/examples/rtf2pdf.sh" (1 Feb 2013, 3466 Bytes) of package /linux/misc/old/ted-2.23-linux-amd64.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 ########################################################################
    4 #
    5 #  Convert an rtf document to pdf format using 'Ted' and 'GhostScript'.
    6 #
    7 #  Usage    rtf2pdf.sh --paper paper something.rtf something.pdf
    8 #  Or       rtf2pdf.sh something.rtf something.pdf
    9 #
   10 #  Valid values for paper are a4, a5, a6, letter, legal and executive
   11 #
   12 #  This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
   13 #  'Ted' documentation.
   14 #
   15 #  If you want 'Ted' to set configurable resources, use
   16 #  Ted  --printToFilePaper --setProperty ... in the Ted way. E.G:
   17 #  Ted  --setProperty usePostScriptFilters 1 \
   18 #   --setProperty usePostScriptIndexedImages 1  \
   19 #   --setProperty afmDirectory /usr/share/ghostscript/fonts  \
   20 #   --setProperty fontDirectory /usr/share/ghostscript/fonts  \
   21 #   --setProperty ghostscriptFontmap \
   22 #               /usr/share/ghostscript/6.53/lib/Fontmap \
   23 #   --setProperty ghostscriptFontToXmapping \
   24 #               /usr/share/ghostscript/6.53/lib/fonts.dir \
   25 #   --printToFilePaper .....
   26 #  The settings can also be stored in /usr/share/Ted/Ted.properties or in 
   27 #  $(HOME)/.Ted.properties files. Refer to the Ted documentation for 
   28 #  more details.
   29 #
   30 #  This script uses the --printToFile invocation rather than the --saveTo 
   31 #  invocation to use an explicit paper size or the default one of the machine.
   32 #  Ted --saveTo this.rtf that.pdf produces a PDF file with the paper size 
   33 #  of the rtf input document.
   34 #
   35 #  NOTE: If you use this script from an internet scripting environment with 
   36 #   a limited environment such as PHP, make sure that Ted, gs and basename
   37 #   can be found via the PATH environment variable.
   38 #
   39 #  The file /usr/share/ghostscript/version/doc/Ps2pdf.htm documents 
   40 #  many settings for ghostscript that influence the generation of pdf.
   41 #  The actual meaning of the parameters is explained in Adobe technical 
   42 #  note #5151: "Acobat Distiller Parameters". With some effort, note #5151 
   43 #  can be found using the search facility on www.adobe.com.
   44 #
   45 #  To disable jpeg compression of 8 bit per component images:
   46 #      -dAutoFilterColorImages=false -dEncodeColorImages=false
   47 #  or
   48 #      -dAutoFilterColorImages=false -sColorImageFilter=FlateEncode
   49 #  to enable: (default)
   50 #      -dAutoFilterColorImages=true
   51 #
   52 #  To produce uncompressed pdf:
   53 #      -dCompressPages=false
   54 #  To produce compressed pdf: (default)
   55 #      -dCompressPages=true
   56 #
   57 #  Depending on your temper, you could also have a look at the pdfopt script
   58 #
   59 ########################################################################
   60 
   61 PAPER=
   62 PARAMS="--usePostScriptFilters=1 --usePostScriptIndexedImages=1"
   63 
   64 ps=/tmp/$$.ps
   65 trap "rm -f ${ps}" 0
   66 
   67 case $# in
   68     1|2)
   69     ;;
   70     3|4)
   71     case $1 in
   72         --paper)
   73         ;;
   74         *)
   75         echo $0: '$1='$1 'Expected --paper'
   76         exit 1
   77         ;;
   78     esac
   79 
   80     case $2 in
   81         a4|a5|a6|letter|legal|executive)
   82         PAPER=$2
   83         ;;
   84         *)
   85         echo $0: '$2='$2 'Expected a4|a5|a6|letter|legal|executive'
   86         exit 1
   87         ;;
   88     esac
   89     shift; shift;
   90     ;;
   91     *)
   92     echo $0: '$#='$#
   93     exit 1
   94     ;;
   95 esac
   96 
   97 case $# in
   98     1)
   99     rtf="$1";
  100     pdf=`basename "$1" .rtf`.pdf
  101     ;;
  102     2)
  103     rtf="$1";
  104     pdf="$2";
  105     ;;
  106     *)
  107     echo $0: '$#='$#
  108     exit 1
  109     ;;
  110 esac
  111 
  112 case $PAPER in
  113     ?*)
  114     Ted ${PARAMS} --printToFilePaper "$rtf" "$ps" $PAPER
  115 
  116     gs -q   -dNOPAUSE               \
  117         -sDEVICE=pdfwrite           \
  118         -sPAPERSIZE=$PAPER          \
  119         -sOutputFile="$pdf"         \
  120         "$ps"                   \
  121         -c quit
  122     ;;
  123     *)
  124     Ted ${PARAMS} --printToFile "$rtf" "$ps"
  125 
  126     gs -q   -dNOPAUSE               \
  127         -sDEVICE=pdfwrite           \
  128         -sOutputFile="$pdf"         \
  129         "$ps"                   \
  130         -c quit
  131     ;;
  132 esac
  133