Ask Your Question
1

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

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

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

1 Answer

Sort by » oldest newest most voted
0

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

David gravatar image

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

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
           oDoc.getText().removeTextContent(oImg)
       Next 
    
    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

Comments

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

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

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

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

Question Tools

2 followers

Stats

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

Seen: 2,848 times

Last updated: Mar 26 '16