Ask Your Question

how to load an image as bitmap in a writer document with a macro

asked 2020-12-14 21:55:57 +0100

parsely gravatar image

updated 2020-12-16 16:14:39 +0100

With the GUI i can load an image as a bitmap and assign a name to it. How can this be achieved with a macro, so it can be rerenced later as the background of a frame

Preferably the image is embedded in the document.

edit retag flag offensive close merge delete


When editing a question (or an answer), please make clear what was changed.
Seems you appended frame.FillBitmapName = 'the_new_added_bitmap_name' without explaining the reason.
It may not work this way. Terminology develops, and misconceptions survive.
Did you read my answer?
Did you read Andrew's text?
Please explain in what way the mentioned information was insufficient for you. After all I reported that my code actually worked - and that wasn't a lie. I made the time to test.
Anyway: I feel sure you won't succeed without using the BitMapTable service. The recommendation to use the myFrame.BackGraphic-property in LibreOffice V 6.1 or higher is from

Lupp gravatar imageLupp ( 2020-12-15 11:04:13 +0100 )edit

Thanks for the API link, i was looking for that.

Sorry to caused confusion, there is a difference in skills between us (20.000 to 38), so it stems from ignorance of LO macros. I have no education in programming, it is very hard to get hold of the concepts of API, services, structs, frames, interfaces, UNO and so on, leave alone how these are related. Documentation with boxes and arrows starts at quite a skilled level, and is assuming you are already familiar with the principles. I work in a mixture of reading documentation, examples in the forum, MRI and trial and error.
By MRI i found that property FillBitmapName was identical to a manually set bitmap name, eg. the name 'fence' or 'paper' appeared. It brought the visual result wanted (Version:, and yes the image was added to the bitmap first )
Your approach is ...(more)

parsely gravatar imageparsely ( 2020-12-16 13:11:51 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-12-14 23:25:08 +0100

Lupp gravatar image

I don't feel sure to understand, but what Andrew Pitonyak described under 5.9.1 of his "Useful Macro Information" actually worked for me (slightly adapted) in a test.

The strange thing troubling me is that I need to create the BitmapTable also to get access to already loaded images. If such a table was created during a previous run of a respective Sub, and got inserted an image, this image is present next time when I "create" the table again.

I would expect to get access to the previously created BitmapTable in a similar way as to a DrawPage or to the TextTables container.

Sub demo()
doc = ThisComponent
bmt = doc.createInstance("")
bmt.insertByName("jpg1", ConvertToURL("C:\Users\myFolderPathToTheImage\IMG_8283.jpg"))
REM A later attempt to insert an image under the same name int a newly "created" bmt will cause an error.
fr1 = doc.TextFrames.getByName("Frame1") REM The frame was created and named previously.
internalJpg1 = bmt.getByName("jpg1")
fr1.BackGraphic = internalJpg1
End Sub
edit flag offensive delete link more


Thanks Lupp. I tried about an identical code, without the ConvertToUrl , then it doesn.t work wthout an error message
In python uno.systemPathToFileUrl( filename)
Now I will try answer another question about inserting a barcode barcode question

parsely gravatar imageparsely ( 2020-12-15 11:16:37 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-12-14 21:55:57 +0100

Seen: 38 times

Last updated: Dec 16 '20