Batch conversion from odp to png

I would like to automate the export of my slides to png.
So far I found the great command (I didn’t expect LO to expose this):
$ libreoffice --convert-to png ./zaza.odp
My problem is that it only exports the first slide. Ideally I would like to have zaza0.png, zaza1.png,… for slides 0 and 1 respectively.

Here is the odp in question:

I run LibreOffice 20m0(Build:2) on Ubuntu 16.10

Nb: libreoffice --headless outputs no warning when it fails. Apparently it was because I already had a LO running

I made a slight modification to a macro that I created to save each slide as bmp files to save as png files.

Edit to show how to call from command line.

"C:\Program Files\LibreOffice 5\program\soffice.exe" --headless zaza.odp macro:///Standard.WritePNGSlides.WritePNGSlides()

Assuming the macro code is saved in libreoffice application, My Macros & Dialogs, Standard library in module named WritePNGSlides.

Code below modified to close the document after export.

Sub WritePNGSlides()

	Dim oDoc As Object
	Dim oSlide As Object
	Dim oDrawPages As Object
	Dim oFilter As Object
	Dim Args(2) As New
	Dim sDirectory As String
	Dim sFileName As String
	Dim i As Integer
	oDoc = thisComponent
	If oDoc.Identifier <> "" Then
		msgbox "Only PresentationDocument type is supported"
		Exit Sub
	End If
	If oDoc.Location = "" Then
		msgbox	"Save the presentation to a folder where we will save the slide images."
		Exit Sub
	End If
	sFileName = oDoc.Title
	sDirectory = replace(oDoc.Location, "%20", " " )	'	Allow for spaces in name as %20'
	sDirectory = replace(sDirectory, sFileName, "" )
	sFileName = left(sFileName, instr(sFileName,".") - 1)
	oDrawPages = oDoc.getDrawPages
	For i = 0 To oDrawPages.Count - 1
		oSlide = oDrawPages.getByIndex(i)
'		msgbox "test calling macro from command line" & chr(10) &		'	Debug only
		Args(0).Name = "URL"
		Args(0).Value = sDirectory & sFileName & "_" & & ".png"
		Args(1).Name = "MediaType"
		Args(1).Value = "image/png"
		Args(2).Name = "Overwrite"
		Args(2).value = false
	Next i
	'	Enable the following line if you call macro from windows batch file '
End Sub

Thanks for sharing this macro. I understand from your comment that it is the expected behavior for libreoffice to just export/convert the first slide ?! (awkward I would say). Else I am a very casual LO user, is there anyway to run your macro from the command line ?

It might be possible without macro, but I don’t know how to do that, maybe someone else will have a method.

Thanks it works great ! I was just surprised at first that it closed libreoffice (when ran from libreoffice).
The command line doesn’t work here because I don’t have a JRE and it is a show stopper apparently. I had a warning message about the missing JRE in the gui, yet I was able to execute your script.
I consider this solved anyway thanks again !