Benutzer:PBriehl/Scripte/doc2pdf

Microsoft schriftarten installieren! aptitude install msttcorefonts

cups-pdf

Vorbereitung

cups-pdf installieren

aptitude install cups-pdf
PDFDrucker einrichten

evtl. in /etc/cups/cups-pdf.conf mit Out oder Spool das Output- bzw. Spool-Verzeichnis ändern.

lpadmin -p pdfdrucker -v cups-pdf:/ -E

OpenOffice installieren

aptitude install openoffice.org

Minimal ohne X

aptitude install openoffice.org-writer openoffice.org-headless

Bevor OpenOffice 2.3 aptitude install openoffice.org-writer xvfb

Script ist entsprechend an zu passen.

Script

#!/bin/bash

if [ $# -eq 0 ]; then
    echo "Usage: `basename $0` file [file2] [file3] ..." 2>&1
    exit 1
elif [ $# -gt 1 ]; then
    for i in $*
    do
        echo $i
        $0 "$i"
    done
    exit
fi

ispdf=`echo "$1" | grep -c "\.pdf$"`
if [ $ispdf -eq 1 ]; then
    echo "$1 already is a PDF Document." 2>&1
    exit 2
fi

DIR=`dirname $1`
[ "$DIR" == "." ] && DIR=$(pwd)
BNAME=`basename "$1"`
DOC="$DIR/$BNAME"
CUPSOUT="/var/spool/cups-pdf/${USER}"
PDF="$CUPSOUT/${BNAME%.*}.pdf"

if [ -e "$PDF" ]; then
    echo "$(basename $PDF) already exists in $DIR" 2>&1
    exit 3
fi

/usr/bin/ooffice -headless -invisible -norestore -pt pdfdrucker $DOC
sleep 1
mv $PDF $DIR

Probleme

  • Drucken mit lp gibt leere PDFDokumente aus
  • Muss über Office Anwendung gedruckt werden
  • Bis OpenOffice.org 2.3 X bzw. Xvfb benötigt

antiword

Tipp von http://www.perlmonks.org/?node_id=597581

Script

#!/bin/bash
LANG=C

if [ $# -eq 0 ]; then
	echo "Usage: `basename $0` file [file2] [file3] ..." 2>&1
	exit 1
elif [ $# -gt 1 ]; then
	for i in $*
	do
		echo $i
		$0 "$i"
	done
	exit
fi
lpadmin -p pdfdrucker -v cups-pdf:/ -E
ispdf=`echo "$1" | grep -c "\.pdf$"`
if [ $ispdf -eq 1 ]; then
	echo "$1 already is a PDF Document." 2>&1
	exit 2
fi

DIR=`dirname $1`
[ "$DIR" == "." ] && DIR=$(pwd)
BNAME=`basename "$1"`
DOC="$DIR/$BNAME"
PDF="$DIR/${BNAME%.*}.pdf"

if [ -e "$PDF" ]; then
	echo "$(basename $PDF) already exists in $DIR" 2>&1
	exit 3
fi

/usr/bin/antiword -a A4 $DOC > $PDF

Probleme

  • Wenn Dokument mit Leerzeile anderer Schriftart beginnt
  • Tabellen

OpenOffice.org

Von http://www.togaware.com/linux/survivor/Convert_MS_Word.html

Vorbereitung

OpenOffice.org Macro

REM  *****  BASIC  *****

Sub ConvertWordToPDF(cFile)
  cURL = ConvertToURL(cFile)
  
  ' Open the document.
  ' Just blindly assume that the document is of a type that OOo will
  '  correctly recognize and open -- without specifying an import filter.
  oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True), ))

  Dim compsn
     oPropertyV
  comps = split (cFile, ".")
  If UBound(comps) > 0 Thenn
     oPropertyV
      comps(UBound(comps)) = "pdf"
      cfile = join (comps, ".")
  Else
      cfile = cFile + ".pdf"
  Endif

  cURL = ConvertToURL(cFile)
  
  ' Save the document using a filter.
  oDoc.storeToURL(cURL, Array(MakePropertyValue("FilterName", "writer_pdf_Export"), ))

  oDoc.close(True)

End Subn
     oPropertyV

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
  Dim oPropertyValue As New com.sun.star.beans.PropertyValue
  If Not IsMissing( cName ) Then
     oPropertyValue.Name = cName
  EndIf
  If Not IsMissing( uValue ) Then
     oPropertyValue.Value = uValue
  EndIf
  MakePropertyValue() = oPropertyValue
End Function

Script

#!/bin/bash
if [ $# -eq 0 ]; then
	echo "Usage: `basename $0` file [file2] [file3] ..." 2>&1
	exit 1
elif [ $# -gt 1 ]; then
	for i in $*
	do
		echo $i
		$0 "$i"
		sleep 3
	done
	exit
fi

isdoc=`echo $1 | grep -c "\.doc$"`
if [ $isdoc -ne 1 ]; then
	echo "file must be \"*.doc\"" 2>&1
	exit 2
fi

DIR=`dirname $1`
[ "$DIR" == "." ] && DIR=$(pwd)
DOC=$DIR/`basename $1`

/usr/bin/oowriter -invisible "macro:///Standard.Module1.ConvertWordToPDF($DOC)"

Probleme

  • Bis OpenOffice.org 2.3 X bzw. Xvfb benötigt
  • Buggy