How many degrees of headlessness do we need? [and LibreOffice crash]

Piet van Oostrum piet at vanoostrum.org
Wed Apr 1 02:07:45 PDT 2015


Michael Stahl wrote:

 > actually now i tried it out and the crash was pretty trivially fixed
 > with commit d360477d8740f29e2c2bc5f7bbd667df7cd26ee9
 > 
This is great! It works!

So now I have one more way to process a document "headless". And now no weird window will be created.

Code for reading a document:

------------------------------------------------------------------------ 
textdoc = ServiceManager.createInstance("com.sun.star.text.TextDocument")

loadURL = systemPathToFileUrl(realpath("test.odt"))
inProps = (PropertyValue("URL", -1, loadURL, 0), PropertyValue("FilterName", -1, "writer8", 0))
textdoc.load(inProps)

print(textdoc.Text.String)

textdoc.close(True)
------------------------------------------------------------------------


Code for writing a document:
------------------------------------------------------------------------
textdoc = ServiceManager.createInstance("com.sun.star.text.TextDocument")

textdoc.initNew()
textdoc.Text.String = "Hello World from initNew()"

saveURL = systemPathToFileUrl(realpath("test.odt"))
outProps = PropertyValue("Overwrite", -1, True, 0), # 1-tuple
textdoc.storeAsURL(saveURL, outProps)

textdoc.close(True)
------------------------------------------------------------------------

Even with a non-headless LO start (but with --nologo --nodefault) no window is created.
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]


More information about the LibreOffice mailing list