LibreOffice Writer has the ability to compress (resize) image through dialog “Compress Image…” (right click on image, select in context menu “Compress Image…”).
Same dialog can be open by UNO command - .uno:CompressGraphic. For example, dispatcher.executeDispatch(document, “.uno:CompressGraphic”, “”, 0, Array()). But this command does not accept any parameters, core/svx.sdi at master · LibreOffice/core · GitHub
Is there any way to automate the task? Macros? Basic, Python, Java?
In what direction to search? What to read, articles, books, guidelines.
Sub Snippet(Optional oInitialTarget As Object)
Dim oDrawPage As Variant
Dim oObj1 As Variant
Dim aSize As New com.sun.star.awt.Size
oDrawPage = ThisComponent.getDrawPage()
'Get item to resize'
oObj1 = oDrawPage.getByIndex(1)
'Set width and height'
oObj1.Width = 1280
oObj1.Height = 1080
End Sub
Edit: Same but find item by Name:
Sub Snippet2(Optional oInitialTarget As Object)
Dim oDrawPage As Variant
Dim oObj1 As Variant
Dim aSize As New com.sun.star.awt.Size
Dim sName As String
Dim nCount As Long
oDrawPage = ThisComponent.getDrawPage()
nCount = oDrawPage.getCount()
For x = 0 to nCount -1
oObj1 = oDrawPage.getByIndex(x)
sName = oObj1.getName()
if sName = "Image1" Then
oObj1.Width = 1280
oObj1.Height = 1080
Exit For
End If
Next x
End Sub
Thank you very much for your attention and help! But as I understand this is not change the “actual size” of image – just resize “frame”. The embedded image (inside odt) still have the original size and quality. If I will open dialog “Compress Image”, image capacity will be as originally
A bit more info for you. The source for the dialog processing: click here.
The dialog ui (with defaults) is in the installation under /opt/libreoffice5.1/share/config/soffice.cfg/svx/ui/compressgraghicdialog.ui (linux location).
As I see it, three choices: compile your own LO version with necessary modifications, change defaults in dialog, or create you own routine based upon the one in LO.