Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello @shystar, and welcome to the Ask.LibreOffice forum!

To shrink ( or enlarge ) the selected images in the current Writer document, you could use the following Basic macro:

Sub Writer_Resize_Selected_Images( dPercentage As Double )
REM Resizes selected Images in the current Writer document.
REM <dPercentage>   : Factor by which to scale each image ( 1.0 = 100% ).
    Dim oDoc As Object       : oDoc = ThisComponent
    Dim oSelection As Object : oSelection = oDoc.CurrentSelection
    Dim oSel As Object
    Dim oEnum As Object
    Dim oEnum2 As Object
    Dim oEnum3 As Object
    Dim oParagraph As Object
    Dim oContent As Object
    Dim oPortion As Object
    Dim aNewSize As New com.sun.star.awt.Size
    Dim i As Integer
    If oSelection.supportsService( "com.sun.star.text.TextGraphicObject" ) Then
        aNewSize.Width = oSelection.Size.Width * dPercentage
        aNewSize.Height = oSelection.Size.Height * dPercentage
        oSelection.setSize( aNewSize )
    ElseIf oSelection.supportsService( "com.sun.star.text.TextRanges" ) Then
        For i = 0 To oSelection.getCount() - 1          REM Traverse Selections.
            oSel = oSelection.getByIndex( i )
            oEnum = oSel.createEnumeration()
            Do While oEnum.hasMoreElements()            REM Traverse Paragraphs.
                oParagraph = oEnum.nextElement()
                oEnum2 = oParagraph.createEnumeration()
                Do While oEnum2.hasMoreElements()       REM Traverse TextPortions.
                    oPortion = oEnum2.nextElement()
                    oEnum3 = oPortion.createContentEnumeration( "com.sun.star.text.TextContent" )
                    Do While oEnum3.hasMoreElements()   REM Traverse TextContents.
                        oContent = oEnum3.nextElement()
                        If oContent.supportsService( "com.sun.star.text.TextGraphicObject" ) Then
                            aNewSize.Width = oContent.Size.Width * dPercentage
                            aNewSize.Height = oContent.Size.Height * dPercentage
                            oContent.setSize( aNewSize )
                        End If
                    Loop
                Loop
            Loop
        Next i
    End If
End Sub

With Regards, lib