Ok, so here's the macro and the script to go with it ( as suggested by
my only replier earlier with a little tweaking on my part): This is based on code found at http://www.oooforum.org/forum/viewtopic.phtml?t=3772 with a little tweaking on my part. To add more file types to be able to convert you would need to tweak the File2PDF Subroutine and then add the requisite Functions that went with the tweak (if needed). I put the following in my ~/.openoffice.org2.0/user/basic/Standard/Module1.xba file. Sub File2PDF( cFile ) ' Set output file extension based on lower-case ' version of input extension. Select Case LCase(Right(cFile,3)) Case "ppt" ' PowerPoint file. PptToPDF(cFile) Case "doc" ' Word file. DocToPDF(cFile) Case "xls" ' Excel file. XlsToPDF(cFile) End Select End Sub Function PptToPDF( 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. oPpt = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_ MakePropertyValue( "Hidden", True ),_ ) ) cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) ' Save the document using a filter. oPpt.storeToURL( cURL, Array(_ MakePropertyValue( "FilterName", "draw_pdf_Export" ),_ ) oPpt.close( True ) End Function Function XlsToPDF( 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. oXls = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_ MakePropertyValue( "Hidden", True ),_ ) ) cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) ' Save the document using a filter. oXls.storeToURL( cURL, Array(_ MakePropertyValue( "FilterName", "calc_pdf_Export" ),_ ) oXls.close( True ) End Function Function DocToPDF( 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 ),_ ) ) cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) ' Save the document using a filter. oDoc.storeToURL( cURL, Array(_ MakePropertyValue( "FilterName", "writer_pdf_Export" ),_ ) oDoc.close( True ) End Function 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 To make it even easier I then created a script called file2pdf that does the following: #!/bin/bash if [ -z "$1" ] then echo "Usage: $0 <file>" exit -1 fi DISPLAY=:0 export DISPLAY DOC=$1 DOC_dir=`dirname $DOC` if [ "$DOC_dir" = "." ] ; then DOC=`pwd`/$DOC fi /usr/lib/openoffice.org/program/soffice -invisible "macro:///Standard.Module1.File2PDF($DOC)" exit $? So then I just run my file2pdf script and pass it the file name (either fully path qualified or not). Enjoy. Kevin Kevin Martin wrote: Ok, so it was actually "openoffice converting files to pdf..." but what the heck. |
-- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list