Hey, as title said, how would I go about removing all the pictures from a document in LibreOffice Writer?
Thank you.
Hey, as title said, how would I go about removing all the pictures from a document in LibreOffice Writer?
Thank you.
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.
Click on Tools > Macros > Organise macros > LibreOffice Basic...
(a new window opens).
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”.
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.
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
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.
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:
Customise > Menus
, then choose the menu you want to add your macro to from the Menu drop-down. I used “Edit”.Add...
button on the right of the dialog, and scroll to the bottom of the “Category” listing until you see > LibreOffice Macros
.My Macros > Standard > Module 1
. You should now see “RemoveImages” listed in the right-hand “Commands” box. Click on it to select it.Add
button (which will add the macro to your chosen menu), then Close
, to close the “Add Commands” dialog.⇧
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.
thanks this works perfectly.
i would upvote but i dont have enough rep
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?
I could hit that heart button a hundred times or more. Thank you!!
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)
oDrawPage.remove(oShape)
Next iShape
Next iSheet
End Sub
getByIndex(i)
is likely wrong - needs to be getByIndex(iShape)
And use Long
, not Integer
.