Ask Your Question

Batch conversion from odp to png [closed]

asked 2016-10-18 16:39:27 +0200

mattator gravatar image

updated 2020-09-13 22:20:07 +0200

Alex Kemp gravatar image

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

edit retag flag offensive 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

1 Answer

Sort by » oldest newest most voted

answered 2016-10-18 17:17:33 +0200

mark_t gravatar image

updated 2016-10-19 03:42:57 +0200

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
edit flag offensive delete link 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 ?

mattator gravatar imagemattator ( 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.

mark_t gravatar imagemark_t ( 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 !

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

Question Tools

1 follower


Asked: 2016-10-18 16:39:27 +0200

Seen: 828 times

Last updated: Oct 19 '16