Wednesday, 5 June 2019

unotools insert image into document (libreoffice)

I'm trying to insert an image into a libreoffice document that is handled/controlled by unotools.

Therefore I start LibreOffice with this command:

soffice --accept='socket,host=localhost,port=8100;urp;StarOffice.Service'

Inside my python code I can connect to LibreOffice:

from unotools import Socket, connect
from unotools.component.writer import Writer
context = connect(Socket('localhost', 8100))
writer = Writer(context)

(This code is taken from this documentation: https://pypi.org/project/unotools/)

By using writer.set_string_to_end() I can add some text to the document. But I also want to insert an image into the document. So far I couldn't find any resource where this was done. The image is inside of my clipboard, so ideally I want to insert the image directly from there. Alternatively I can save the image temporarily and insert the saved file.

Is there any known way how to insert images by using unotools? Any alternative solution would also be great.



from unotools insert image into document (libreoffice)

No comments:

Post a Comment