Ask Your Question

Automatization “Compress Image” in LibreOffice Writer (macro or any method)

asked 2016-07-20 09:51:14 +0100

unit gravatar image

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,

Is there any way to automate the task? Macros? Basic, Python, Java? In what direction to search? What to read, articles, books, guidelines.


Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-07-20 19:40:55 +0100

Ratslinger gravatar image

updated 2016-07-20 20:42:31 +0100

You can set size with following:

    Sub Snippet(Optional oInitialTarget As Object)
       Dim oDrawPage As Variant
       Dim oObj1 As Variant
       Dim aSize As New
       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
  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
edit flag offensive delete link more


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

unit gravatar imageunit ( 2016-07-20 21:17:15 +0100 )edit

You are correct. A little too quick with the answer.

Ratslinger gravatar imageRatslinger ( 2016-07-20 21:53:51 +0100 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-07-22 16:40:39 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-07-20 09:51:14 +0100

Seen: 347 times

Last updated: Jul 20 '16