Modify Open Office with appropriate macros

Determine which user will be using Open Office and open the program from that account

If you do not have setuid installed and the web server is running under 'nobody', then you can create a special user that will be responsible for handling the conversion of the documents. In either case, you need to create an OpenOffice.org Basic macro.

From the Open Office window, select Tools > Macros > Organize Macros > OpenOffice.org Basic

image of edit window

We are going to edit Module1's 'Main' macro. Select 'Edit' button from right menu.

Overwrite the contents of this module with the following:


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

Sub ConvertToPDF( cFile )
   cURL = ConvertToURL( cFile )
 '  MsgBox( cURL )
 ' 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", False )) )

   cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
   cURL = ConvertToURL( cFile )

   oDoc.storeToURL( cURL, Array(_
            MakePropertyValue( "FilterName", "writer_pdf_Export" ))

   oDoc.close( True )
End Sub

Sub ConvertToDOC( cFile )
   cURL = ConvertToURL( cFile )
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(MakePropertyValue( "Hidden", True )) )
   cFile = Left( cFile, Len( cFile ) - 4 ) + ".doc"
   cURL = ConvertToURL( cFile )
   oDoc.storeToURL( cURL, Array(_
            MakePropertyValue( "FilterName", "MS Word 97" ))
  oDoc.close( True )
End Sub


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
Sub Main

End Sub

Save and Exit, your macro is now ready for use!