Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 12102  / 2 Years ago, sun, september 18, 2022, 7:36:11

Ubuntu 12.04



I want to remove all the images from a document in LibreOffice Writer. My document contains ~ 350 images. Is there a way to delete them en masse rather than one by one? I tried unchecking Tools > Options > LibreOffice Writer > View > Display > "Graphics and objects". But the place-holders are still visible.



Edit: I know about saving the page as a plain text file, But I need formatting in my document.


More From » libreoffice

 Answers
6

You can also use a short macro from within LibreOffice to remove all images in a document:



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


This example could also be modified to change the properties of images (such as making them all a uniform size) as well as handling shape objects, etc.



Creating Macros



LibreOffice provides a Basic language as well as in IDE to create, debug, store, and run code.



To open the macro dialog, use Alt + F11 or, from the menu, Tools > Macros > Organize Macros > LibreOffice Basic



Code is placed in modules, which are organized into libraries. You can create your own, but for most purposes you can use the built-in MyMacros library and the built-in Module1.



Once the macro dialog is open, highlight Module1 and press Edit. This opens the IDE.



Code is organized into Subs and Functions. Borrowing from VBA, Functions are used to return a value and Subs do not return a value. You can define your own subs and functions anywhere below Main. So to use this code to remove images, you just paste it in the module.



Using Macros



You can run the code right from the IDE by clicking anywhere inside the Sub you want to run and press F5. (Functions, since they return a value, need to be called from a Sub.) You can also use the dialog buttons or menu to run the code. The IDE includes an integrated debugger, which is crucial when writing new code.



The next time you open the macro dialog, you will see the sub listed as a macro and it can then be run without opening the IDE. Individual macros can also be assigned to menu or toolbar items.



Note: This macro will run on whatever is the active document. When running a macro from the menu or macro dialog, this can be assumed to be the document where you just pressed the button; but when using the IDE to create, run, or debug code, make sure you haven't made another document the active document.



LibreOffice Basic



LibreOffice Basic is very similar to VBA, but that similarity can also be deceiving since the object model is completely different and the syntax also has many differences.



For example, in VBA, once you have a reference to an image object, the image object would have a delete method. Here, objects have or inherit very few methods. To delete the image object, you use the document element with a structure and syntax very similar to a browser-based DOM.



LibreOffice Help has links for getting started with LibreOffice Basic.


[#32551] Monday, September 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dresuitable

Total Points: 69
Total Questions: 116
Total Answers: 122

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
dresuitable questions
Sat, May 15, 21, 04:38, 3 Years ago
Fri, Apr 14, 23, 09:53, 1 Year ago
Tue, May 16, 23, 18:13, 1 Year ago
Sun, Apr 24, 22, 12:59, 2 Years ago
;