giovedì 9 febbraio 2012

Installazione pacchetto ted per la conversione di rtf in pdf

Ted è una Gui per la visualizzazione e la modifica di file Rtf che grazie a degli script permette di convertire tali Rtf in Pdf , Html ecc..

Le dipendenze di questo pacchetto sono:

Per installare il pacchetto ted si deve inanzitutto installare la libreria lesstif2 ( le altre dipenze solitamente sono già soddisfatte


sudo aptitude install lesstif2
 scaricare i pacchetti .deb da launchpad
  • prima di tutto il file ted-common ( al momento siamo alla versione 2.17)

    wget http://launchpadlibrarian.net/11313542/ted-common_2.17-1ubuntu1_all.deb


    sudo dpkg -i ted-common_2.17-1ubuntu1_all.deb
  • nel mio caso devo installare il pacchetto per processore 64bit
    wget https://launchpad.net/ubuntu/+source/ted/2.17-1ubuntu1/+build/489695/+files/ted_2.17-1ubuntu1_amd64.deb

    sudo dpkg -i
    ted_2.17-1ubuntu1_amd64.deb
  • Con i seguenti script è possibile convertire tramite shell i documenti rtf in vari formati.

  1. rtf2pdf.sh
    #!/bin/sh
    
    ########################################################################
    #
    #  Convert an rtf document to pdf format using 'Ted' and 'GhostScript'.
    #
    #  Usage rtf2pdf.sh --paper paper something.rtf something.pdf
    #  Or  rtf2pdf.sh something.rtf something.pdf
    #
    #  Valid values for paper are a4, a5, a6, letter, legal and executive
    #
    #  This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
    #  'Ted' documentation.
    #
    #  If you want 'Ted' to set configurable resources, use
    #  Ted  --printToFilePaper --setProperty ... in the Ted way. E.G:
    #  Ted  --setProperty usePostScriptFilters 1 \
    # --setProperty usePostScriptIndexedImages 1  \
    # --setProperty afmDirectory /usr/share/ghostscript/fonts  \
    # --setProperty fontDirectory /usr/share/ghostscript/fonts  \
    # --setProperty ghostscriptFontmap \
    #    /usr/share/ghostscript/6.53/lib/Fontmap \
    # --setProperty ghostscriptFontToXmapping \
    #    /usr/share/ghostscript/6.53/lib/fonts.dir \
    # --printToFilePaper .....
    #  This has the advantage over the ++printToFilePaper call and X11 
    #  resource settings with -xrm Ted.usePostScriptFilters:1 style arguments 
    #  that it does not require an X11 server.
    #  The settings can also be stored in /etc/Ted.properties or in 
    #  $(HOME)/.Ted.properies files. Refer to the Ted documentation for 
    #  more details.
    #
    #  The file /usr/share/ghostscript/version/doc/Ps2pdf.htm documents 
    #  many settings for ghostscript that influence the generation of pdf.
    #  The actual meaning of the parameters is explained in Adobe technical 
    #  note #5151: "Acobat Distiller Parameters". With some effort, note #5151 
    #  can be found using the search facility on www.adobe.com.
    #
    #  To disable jpeg compression of 8 bit per component images:
    #      -dAutoFilterColorImages=false -dEncodeColorImages=false
    #  or
    #      -dAutoFilterColorImages=false -sColorImageFilter=FlateEncode
    #  to enable: (default)
    #      -dAutoFilterColorImages=true
    #
    #  To produce uncompressed pdf:
    #      -dCompressPages=false
    #  To produce compressed pdf: (default)
    #      -dCompressPages=true
    #
    #  Depending on your temper, you could also have a look at the pdfopt script
    #
    ########################################################################
    
    PAPER=
    PARAMS="--setProperty usePostScriptFilters 1 --setProperty usePostScriptIndexedImages 1"
    
    ps=/tmp/$$.ps
    trap "rm -f ${ps}" 0
    
    case $# in
        1|2)
     ;;
        3|4)
     case $1 in
         --paper)
      ;;
         *)
      echo $0: '$1='$1 'Expected --paper'
      exit 1
      ;;
     esac
    
     case $2 in
         a4|a5|a6|letter|legal|executive)
      PAPER=$2
      ;;
         *)
      echo $0: '$2='$2 'Expected a4|a5|a6|letter|legal|executive'
      exit 1
      ;;
     esac
     shift; shift;
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    case $# in
        1)
     rtf="$1";
     pdf=`basename "$1" .rtf`.pdf
     ;;
        2)
     rtf="$1";
     pdf="$2";
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    case $PAPER in
        ?*)
     Ted ${PARAMS} --printToFilePaper "$rtf" "$ps" $PAPER
    
     gs -q -dNOPAUSE    \
      -sDEVICE=pdfwrite   \
      -sPAPERSIZE=$PAPER   \
      -sOutputFile="$pdf"   \
      "$ps"     \
      -c quit
     ;;
        *)
     Ted ${PARAMS} --printToFile "$rtf" "$ps"
    
     gs -q -dNOPAUSE    \
      -sDEVICE=pdfwrite   \
      -sOutputFile="$pdf"   \
      "$ps"     \
      -c quit
     ;;
    esac
  2. rtf2ps.sh
    #!/bin/sh
    
    ########################################################################
    #
    #  Convert an rtf document to PostScript format using 'Ted'.
    #
    #  Usage rtf2ps.sh --paper paper something.rtf something.ps
    #  Or  rtf2ps.sh something.rtf something.ps
    #
    #  Valid values for paper are a4, a5, a6, letter, legal and executive
    #
    #  This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
    #  'Ted' documentation.
    #
    #  If you want 'Ted' to set configurable resources, use
    #  Ted  --printToFilePaper --setProperty ... in the Ted way. E.G:
    #  Ted  --setProperty usePostScriptFilters 1 \
    # --setProperty usePostScriptIndexedImages 1  \
    # --setProperty afmDirectory /usr/share/ghostscript/fonts  \
    # --setProperty fontDirectory /usr/share/ghostscript/fonts  \
    # --setProperty ghostscriptFontmap \
    #    /usr/share/ghostscript/6.53/lib/Fontmap \
    # --setProperty ghostscriptFontToXmapping \
    #    /usr/share/ghostscript/6.53/lib/fonts.dir \
    # --printToFilePaper .....
    #  This has the advantage over the ++printToFilePaper call and X11 
    #  resource settings with -xrm Ted.usePostScriptFilters:1 style arguments 
    #  that it does not require an X11 server.
    #  The settings can also be stored in /etc/Ted.properties or in 
    #  $(HOME)/.Ted.properies files. Refer to the Ted documentation for 
    #  more details.
    #
    ########################################################################
    
    PAPER=
    
    case $# in
        1|2)
     ;;
        3|4)
     case $1 in
         --paper)
      ;;
         *)
      echo $0: '$1='$1 'Expected --paper'
      exit 1
      ;;
     esac
    
     case $2 in
         a4|a5|a6|letter|legal|executive)
      PAPER=$2
      ;;
         *)
      echo $0: '$2='$2 'Expected a4|a5|a6|letter|legal|executive'
      exit 1
      ;;
     esac
     shift; shift;
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    case $# in
        1)
     rtf="$1";
     ps=`basename "$1" .rtf`.ps
     ;;
        2)
     rtf="$1";
     ps="$2";
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    case $PAPER in
        ?*)
     Ted --printToFilePaper "$rtf" "$ps" $PAPER
     ;;
        *)
     Ted --printToFile "$rtf" "$ps"
     ;;
    esac
    
  3. rtf2txt
    #!/bin/sh
    
    ########################################################################
    #
    #  Convert an rtf document to plain text format using 'Ted'.
    #
    #  Usage rtf2txt.sh something.rtf something.txt
    #
    #  This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
    #  'Ted' documentation.
    #
    ########################################################################
    
    case $# in
        1)
     rtf="$1";
     txt=`basename "$1" .rtf`.txt
     ;;
        2)
     rtf="$1";
     txt="$2";
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    Ted --saveTo "$rtf" "$txt"
  4. rtftohtml
    #!/bin/sh
    
    ########################################################################
    #
    #  Convert an rtf document to plain text format using 'Ted'.
    #
    #  Usage rtf2txt.sh something.rtf something.txt
    #
    #  This is an example. Refer to http://www.nllgg.nl/Ted/index.html for the
    #  'Ted' documentation.
    #
    ########################################################################
    
    case $# in
        1)
     rtf="$1";
     txt=`basename "$1" .rtf`.html
     ;;
        2)
     rtf="$1";
     html="$2";
     ;;
        *)
     echo $0: '$#='$#
     exit 1
     ;;
    esac
    
    Ted ++saveTo "$rtf" "$html"


Creare .deb da un .tar.gz con checkinstall

Checkinstall è una utilità molto utile per creare pacchetti .deb per Debian o Ubuntu da file .tar.gz (o .tgz) di sorgenti dopo averli compilati nella tua distribuzione.
Praticamente si prepara il pacchetto per un successivo utilizzo senza il bisogno di compilare il tutto sulla tua macchina linux.
Un'altra applicazione di checkinstall è la disinstallazione del pacchetto dopo averlo installato dai sorgenti.
Come avrete notato non tutti i programmi aggiungono la regola "uninstall" al Makefile e quindi il comando "make uninstall" non andrebbe a buon fine.
La soluzione migliore è utilizzare checkinstall pre preparare i pacchetti dai sorgenti e installarli e disinstallarli con dpkg.
Questa procedura spiga come preparare il .deb di clamav dai sorgenti
  1. installare checkinstall
    sudo aptitude -y install checkinstall
    (Ubuntu, Debian e derivate)
  2. Reperire i sorgenti da installare
    wget http://mesh.dl.sourceforge.net/sourceforge/clamav/clamav-0.81.tar.gz (per esempio)
  3. Installare le dipendenze e le librerie che servono per il funzionamento del pacchetto
    sudo aptitude install libgmp3 libgmp3-dev
  4. Compilare i sorgenti
    tar xvfz clamav-0.81.tar.gz
    cd clamav-0.81/
    ./configure --sysconfdir=/etc
    make
  5. Esegui checkinstall e segui le istruzioni (descrizione pacchetto ecc..):
    sudo checkinstall -D make install
  6. Quando sarà finito avremo clamav-0.81_0.81-1_i386.deb e si potrà installarlo con sudo dpkg -i clamav-0.81_0.81-1_i386.deb oppure copiarlo su un'altro computer per un'altra installazione.