I’m working on an extension using a BASIC Macro that adds a preset image into a Writer document, but I can’t find a way to add the image from the extension itself, only from a predetermined location.
Here’s my code so far:
Sub add_image()
doc = ThisComponent
text = doc.CurrentSelection.getByIndex(0).End
image = doc.createInstance("com.sun.star.text.GraphicObject")
image.GraphicURL = ConvertToURL("C:\images\image.png")
image.Width = 2015
image.Height = 705
cursor = doc.Text.createTextCursorByRange(text)
doc.Text.insertTextContent(cursor, image, False)
End Sub
I’ve tried relative addressing (images/image.png
), using %origin%/images/image.png
, and making the GraphicURL a base64 encoded version of the image, but none of these work (instead of the image it says “Read Error”). It would also be possible to use PathSubstitution
to find $(user)
, but I can’t see how to find the extension ID to get the location the extension has been installed to, and am not sure if this would work on all OSes.
Is it possible, or is an absolute URL the only way to add an image?