in a Writer document, I've written a macro that inserts an image in a TextFrame and adds a caption. Within the macro, I have access to the TextFrame object and I can manipulate it.
Now, I'd like to resize the image within the TextFrame (but not the size of the frame itself). I didn't find any way to do this because I don't know how to access the image within the TextFrame object.
I'll be grateful, if someone could point me in the right direction to solve this issue...
Here is my rather simple code:
Code: Select all
sub InsertFigure
Dim document as object
Dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file://" & environ("HOME") & "/figure.png"
args1(1).Name = "FilterName"
args1(1).Value = "<Tous les formats>"
args1(2).Name = "AsLink"
args1(2).Value = false
args1(3).Name = "Style"
args1(3).Value = "Images"
' Insert image and anchor it to the page
dispatcher.executeDispatch(document, ".uno:InsertGraphic", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:SetAnchorToPage", "", 0, Array())
Dim oDocCtrl as Object
oDocCtrl = ThisComponent.getCurrentController()
' Select frame and center it horizontally
' at 4 cm from the top
Dim oSelection as Object
oSelection = oDocCtrl.getSelection()
oSelection.TextWrap = 0
oSelection.HoriOrient = 2
oSelection.VertOrient = 0
oSelection.VertOrientPosition = 4000
end sub