The macro defined below accepts a file name as an argument, converts it to an associated Pdf file and exits.
REM ***** BASIC *****
Sub SaveAsPDF( cFile )
' cFile = "/home/lipeltgm/sample.odt"
cURL = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( ConvertToUrl( cFile ), "_blank", 0, Array())
cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
cURL = ConvertToURL( cFile )
oDoc.storeToURL( ConvertToUrl( cFile ), Array(MakePropertyValue( "FilterName", "writer_pdf_Export" )))
Shell("pkill soffice.bin")
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
Execute the macro from the command line as follows:
$ soffice -invisible "macro:///Standard.Module1.SaveAsPDF(/home/myUser/sample.odt)"
It's worth noting that the 3rd '/' in 'macro:///' implies the root directory of the application, in this instance the root directory.