Re: openoffice command line printing...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

And I've got it working.  Finally found a macro that would do most of the work and I tweaked it to be "smart" about the conversion process.  So now it works.  If anybody wants the macro, I'll send them the macro file.  Basically what I do is 'soffice -invisible "macro:///......FileToPDF(/<pathtofile>)"' and, based on the extension of the file (.doc, .xls, .ppt) the macro calls the necessary oo function to do the conversion and save the pdf file back to the same directory as the original file.  FWIW, there was no need to setup a dummy X server since I'm running an X server anyway.

Thanks.

Kevin

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux