Ask Your Question

[Writer] How to remove all pictures from a document?

asked 2015-09-06 19:24:28 +0100

romseguy gravatar image

Hey, as title said, how would I go about removing all the pictures from a document in LibreOffice Writer?

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2020-02-14 12:52:26 +0100

Dimoncy gravatar image

updated 2020-02-14 12:53:31 +0100

delete On all pages (works in 2020)

  Sub DeleteAllPics()
        Dim oDoc As Object
        Dim oDrawPage As Object
        Dim oShape As Object
        Dim iShape As Integer
        Dim iSheet As Integer
        oDoc = ThisComponent
        For iSheet = 0 To oDoc.getSheets().getCount() - 1
            oDrawPage = oDoc.getSheets().getByIndex(iSheet).getDrawPage()
            For iShape = oDrawPage.getCount() - 1 To 0 Step -1
                oShape = oDrawPage.getByIndex(i)
            Next iShape
        Next iSheet
    End Sub
edit flag offensive delete link more


getByIndex(i) is likely wrong - needs to be getByIndex(iShape)

And use Long, not Integer.

Mike Kaganski gravatar imageMike Kaganski ( 2020-02-14 13:00:14 +0100 )edit

answered 2016-03-26 15:03:34 +0100

David gravatar image

updated 2016-03-26 15:04:54 +0100

This answer is drawn from "How to remove all the images in a document in LibreOffice Writer?" on AskUbuntu StackExchange. Thanks @chaskes!

The easiest way to do this is via a macro. The following steps will make it availabe as a Toolbar menu item.

  1. Click on Tools > Macros > Organise macros > LibreOffice Basic... (a new window opens).
  2. In the left-hand box, you should see "[+] My Macros". Open that up by clicking on the "plus" sign to get "[+] Standard", open it and see "Module 1", now click on it. You should now see "Main" listed in the right-hand box, "Existing macros in: Module 1".
  3. Click on "Main" in the right-hand box, and now the "Edit" button to the right of it. A new window opens, and in the main text area, you should see "Sub Main" followed a blank line later by "End Sub". Good.
  4. Now we need to get the LO Basic code to paste in below that "End Sub" line. Copy this code block:

    Sub RemoveImages
       Dim oDoc as Object
       oDoc = ThisComponent
       Dim oGraphics as Object
       oGraphics = oDoc.getGraphicObjects()
       Dim oImg as Object
       For Each oImg in oGraphics
    End Sub
  5. Return to the LibreOffice Macro editor, position your cursor under the "End Sub" line, then hit CTRL-V to paste it in. Press CTRL-S to save it.

  6. Close the Macro editor.

You could just run the macro from Tools > Macros > Organise macros > LibreOffice Basic..., click on RemoveImages, then click "Run" (the top button on the right). If you're doing this infrequently, that's probably good enough. If you think you might be using this more often, then it can be assigned to the menus by following these steps:

  1. Go Customise > Menus, then choose the menu you want to add your macro to from the Menu drop-down. I used "Edit".
  2. Click the Add... button on the right of the dialog, and scroll to the bottom of the "Category" listing until you see > LibreOffice Macros.
  3. Click (to open) on My Macros > Standard > Module 1. You should now see "RemoveImages" listed in the right-hand "Commands" box. Click on it to select it.
  4. Click the Add button (which will add the macro to your chosen menu), then Close, to close the "Add Commands" dialog.
  5. You can now use the and buttons to locate the "RemoveImages" macro precisely where you want it in the menu. When finished, click OK.

Removing all the images in your Writer document is now only one click away.

edit flag offensive delete link more


thanks this works perfectly. i would upvote but i dont have enough rep

Overlord_Laharl gravatar imageOverlord_Laharl ( 2017-10-06 01:17:57 +0100 )edit

I tried this (Dec 2017) and got error "BASIC runtime error. Property or method not found: getGraphicObjects" on Windows 7 LO Version: (x64) Any suggestions on how to fix this?

Carrbigdog gravatar imageCarrbigdog ( 2017-12-05 05:03:55 +0100 )edit
Login/Signup to Answer

Question Tools



Asked: 2015-09-06 19:24:28 +0100

Seen: 5,175 times

Last updated: Feb 14 '20