Hi,
I haven’t used the SDK til now, and only need to do one thing: print a selection (not a range) of pages from the command line.
I started libreoffice with:
libreoffice --headless --accept="socket,host=localhost,port=1234;urp"
then ran the following commands (adapted from LibreOffice 24.2 SDK - Examples) in python3 repl:
import uno
import unohelper
from com.sun.star.beans import PropertyValue
local_context = uno.getComponentContext()
resolver = local_context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local_context)
SOFFICE_CONNECTION_URI = "uno:socket,host=localhost,port=1234;urp;StarOffice.ComponentContext"
remote_context = resolver.resolve(SOFFICE_CONNECTION_URI)
soffice = remote_context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", remote_context)
doc_url = "file:///home/user/Documents/test.odt"
doc = soffice.loadComponentFromURL(doc_url, "_blank", 0, tuple([]))
Unfortunately, when I try to print, I get this incomprehensible error:
>>> doc.print(PropertyValue(Name="Pages", Value="1"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
com.sun.star.script.CannotConvertException: conversion not possible! at ./stoc/source/typeconv/convert.cxx:651
The props object looks plausible…
>>> print(props)
(com.sun.star.beans.PropertyValue){ Name = (string)"Pages", Handle = (long)0x0, Value = (any){ (string)"1" }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE }
So, if PropertyValue is the correct argument type, what is wrong? I tried using an integer for the page number, with the same result. According to the example, a range can be specified as ‘1-3’, so I assume a string is acceptable.
Note that I omitted setting the printer name (unlike the example). My LibreOffice has a default printer and specifying a printer by name has seldom if ever worked on my setup…
There were no error messages from the libreoffice process, so I assume the marshaling didn’t get that far, and the exception was thrown by the client, however, there don’t seem to be any debug or verbose command line options for libreoffice, so it’s impossible to say…
Any help would be appreciated!