Python/UNO/OpenOffice?
olive
ocollioud at gmail.com
Mon Oct 2 09:08:03 EDT 2006
John,
Here is something that works for me under XPsp2 to either save a doc or
save it as PDF:
filepath = argv[0]
exportpdf = argv[1]
ctxLocal = uno.getComponentContext()
smgrLocal = ctxLocal.ServiceManager
resolver =
smgrLocal.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",ctxLocal)
url =
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
ctx = resolver.resolve(url)
smgr = ctx.ServiceManager
desktop =
smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)
properties = []
if exportpdf == "yes":
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties.append(p)
properties = tuple(properties)
doc = desktop.loadComponentFromURL("file:///c:"+filepath+".odt" ,
"_blank", 0, properties)
if exportpdf == "yes":
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:///c:"+filepath+".pdf", properties)
else:
doc.store()
doc.dispose()
You must start OO this way first:
cd C:\Program Files\OpenOffice.org 2.0\program
soffice "-accept=socket,host=localhost,port=2002;urp;"
More information about the Python-list
mailing list