Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


Jens Tröger wrote:

I use LO for document analysis (not conversion), i.e. I need to load a
document and poke its styles and also extract some content.  This
*should* run without any GUI because we don't even have the X libs
installed on Linux; works ok so far.  That exact same approach on Mac
*always* pops open a window, which has irritated me for a while.  Good
you mention that this might be broken.
 
If you run LO on the Mac as a service with --headless and you open a doc from a script with 
"Hidden=True", no window will pop up. If the document is open long enough (for example if you put a 
sleep in the script) you can see from the doc that there is an invisible window. From the Dock you 
can open that window. It does have the document filename as title, but it doesn't contain the 
document. It is a kind of strange window. Here is a script that extracts the text from a Writer 
document. Start LO as
/Applications/LibreOffice.app/Contents/MacOS/soffice 
'--accept=socket,host=localhost,port=2002;urp;StarOffice.Servicemanager' --headless 

and run the script with LO's Python:

import uno
from unohelper import systemPathToFileUrl
from com.sun.star.beans import PropertyValue
from os.path import realpath

localContext = uno.getComponentContext()
resolver = 
localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", 
localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

loadURL = systemPathToFileUrl(realpath("test.odt"))
inProps = PropertyValue( "Hidden" , -1 , True, 0 ), # 1-tuple!

textdoc = desktop.loadComponentFromURL(loadURL, "_blank", 0, inProps);
print(textdoc.Text.String)

textdoc.close(True)

-- 
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.