dim noArgs()
dim emptyDocComponent as object
dim document as object
dim dispatcher as object
emptyDocComponent = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
frame = 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://" & inputPath
args1(1).Name = "FilterName"
args1(1).Value = "<All formats>"
args1(2).Name = "AsLink"
args1(2).Value = false
args1(3).Name = "Style"
args1(3).Value = "Graphics"
dispatcher.executeDispatch(frame, ".uno:InsertGraphic", "", 0, args1())
selection = ThisComponent.CurrentSelection
If selection.ImplementationName <> "SwXTextGraphicObject" Then
Exit Sub
End If
' this is what the macro recorder captured, but it was "rem" and non-functional
rem dispatcher.executeDispatch(document, ".uno:Crop", "", 0, Array())
Last edited by Hagar Delest on Mon Sep 04, 2017 10:32 pm, edited 1 time in total.
Reason:tagged [Solved].
selection = ThisComponent.CurrentSelection
If selection.ImplementationName <> "SwXTextGraphicObject" Then
Exit Sub
End If
GrphCrop = selection.GraphicCrop
GrphCrop.TOP = 2500
GrphCrop.BOTTOM = 2500
GrphCrop.LEFT = 2500
GrphCrop.RIGHT = 2500
selection.GraphicCrop = GrphCrop
The units of the cropping seem to be 0.01 mm.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
You have to compensate the cropped parts by changing the image size. I can't remember the exact code but you can find out quite a lot by investigating the code of my macro called pictool: https://extensions.openoffice.org/en/pr ... er-pictool
Appreciate the help. For posterity here is what I came up with. I had a known picture size in pixels that needed to be cropped. Not sure if my calculation is entirely accurate, but it is working so far.