# Batch conversion from odp to png [closed]

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: https://transfer.sh/11nOuP/zaza.odp

I run LibreOffice 5.2.2.2 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

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2020-09-13 22:20:19.272010

Sort by » oldest newest most voted

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 com.sun.star.beans.PropertyValue
Dim sDirectory As String
Dim sFileName As String
Dim i As Integer

oDoc = thisComponent

If oDoc.Identifier <> "com.sun.star.presentation.PresentationDocument" 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

oFilter=CreateUnoService("com.sun.star.drawing.GraphicExportFilter")

For i = 0 To oDrawPages.Count - 1
oSlide = oDrawPages.getByIndex(i)

'       msgbox "test calling macro from command line" & chr(10) & oSlide.name       '   Debug only

oFilter.setSourceDocument(oSlide)

Args(0).Name = "URL"
Args(0).Value = sDirectory & sFileName & "_" & oSlide.name & ".png"
Args(1).Name = "MediaType"
Args(1).Value = "image/png"
Args(2).Name = "Overwrite"
Args(2).value = false

oFilter.filter(args())
Next i

'   Enable the following line if you call macro from windows batch file '
thisComponent.Close(true)
End Sub

more

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 ?

( 2016-10-19 01:28:30 +0200 )edit

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

( 2016-10-19 03:52:35 +0200 )edit

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 !

( 2016-10-19 11:52:29 +0200 )edit