#!/bin/bash
#===============================================================================
#
#          FILE:  convertToPDF.sh
# 
#         USAGE:  ./convertToPDF.sh 
# 
#   DESCRIPTION:  Converts any file the OpenOffice can open to a PDF file
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  John Ryland (jryland@xiaofrog.com)
#       COMPANY:  InvertedLogic
#       VERSION:  1.0
#       CREATED:  06/25/08 17:26:25 CST
#      REVISION:  ---
#===============================================================================

OO_BIN=

if [ "`uname`" == "Linux" ]
then
  OO_BIN=/usr/lib/openoffice/program/soffice
else
  OO_BIN=/Applications/NeoOffice.app/Contents/MacOS/soffice
fi

IN="$1"
OUT="$2"

[ ! -f "$IN" ] && IN="$PWD/$1"
#[ ! -f "$OUT" ] && OUT="$PWD/$2"

if [ -f "$IN" ]
then
    if [ "$2" == "" ]
    then
        echo "Usage: $0 inputfile outputfile"
        exit -1
    fi
    if [ -f "$OUT" ]
    then
        echo "convertToPDF.sh aborting, destination file aready exists, delete first"
        exit -1
    fi
    echo "Converting \"$1\" to PDF"
    $OO_BIN -invisible macro:///Standard.conversions.SaveAsPDF\("$IN","$OUT"\)
else
    echo "Usage: $0 inputfile outputfile"
    exit -1
fi

