This is a very short example I managed to do in not a very long time which does the following things:

  • opens an openoffice draw document
  • modifies a field
  • exports it as ps (using print to file)

Ah, and it does that from an external python program.

The setup

In order to run a python script you need: to set the python path to include the uno lib and start a ooffice server

export PYTHONPATH=/usr/lib/openoffice/basis3.0/program
ooffice -headless -norestore "-accept=socket,host=localhost,port=2002;urp;"

The script

#!/usr/bin/env python
import uno
import unohelper
import sys

from com.sun.star.beans import PropertyValue
from com.sun.star.view import XPrintable

localContext = uno.getComponentContext()                   
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )

smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )

desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)

# open a writer document
doc = desktop.loadComponentFromURL( "file:///home/len/test.odg","_blank", 0, () )

#properties = []
#p = PropertyValue()
#p.Name = "Overwrite"
#p.Value = True
#properties.append(p)
#p = PropertyValue()
#p.Name = "FilterName"
#p.Value = 'writer_pdf_Export'
#properties.append(p)
#properties = tuple(properties)
#doc.storeToURL('file:///home/len/test.pdf', properties)

properties = []
p = PropertyValue()
p.Name = "FileName"
p.Value= "/home/len/Desktop/fax_1.ps"
properties.append(p)
properties = tuple(properties)
uno.invoke(doc, 'print', (properties,))

xdrawpage = doc.getDrawPages().getByIndex(0)
for i in range(xdrawpage.getCount()):
 xshape = xdrawpage.getByIndex(i)
 if xshape.getName() == 'replacethis':
 xshape.setString('myText')

properties = []
p = PropertyValue()
p.Name = "FileName"
p.Value= "/home/len/test.ps"
properties.append(p)
properties = tuple(properties)
uno.invoke(doc, 'print', (properties,))