[Solved] Export slides with animations as images

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
73_ch
Posts: 3
Joined: Tue May 09, 2023 9:21 am

[Solved] Export slides with animations as images

Post by 73_ch »

Hello,

I am looking for a way to export the presentation screen to an image at any given moment in an Impress presentation.

First, I was able to open an Impress document from the command line in Python and play the presentation.
I was also able to export an image as long as all effects for a particular slide were running.

What I would like to do is export the images when there are multiple effects in a slide and I would like to export the images at the stage where each effect has been applied.

Ultimately, I would like to call the animation in which the effects play out in their own draw call and turn it into a GIF or sequentially numbered image.

If anyone has any good ideas, I would be happy to hear them.

For reference, I have included a very rough and quick sample of what we currently have.

Thank you,

Code: Select all

import argparse
import time
import uno
import os
from com.sun.star.beans import PropertyValue

def main():
    parser = argparse.ArgumentParser(description="Document Saver")
    parser.add_argument("src", help="Path to a Word document to be saved, e.g. path/to/hello.doc")
    args = parser.parse_args()

    localContext = uno.getComponentContext()
    resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
    context = resolver.resolve("uno:socket,host=localhost,port=2083;urp;StarOffice.ComponentContext")
    desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
    desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
    exporter = context.ServiceManager.createInstanceWithContext("com.sun.star.drawing.GraphicExportFilter", context)

    # input filepath
    fileUrl = uno.systemPathToFileUrl(os.path.abspath(args.src))

    # open file
    doc = desktop.loadComponentFromURL(fileUrl, "_blank", 0, ())

    presentation = doc.getPresentation()
    presentation.startWithArguments([PropertyValue(Name="IsFullScreen", Value=False)])

    while True:
        if presentation.isRunning():
            controller = presentation.getController()
            slideshow = controller.getSlideShow()

            slideshow.nextEffect()

            for i in range(120):
                slideshow.update(1/60)
                output_path = uno.systemPathToFileUrl(os.path.dirname(os.path.realpath(__file__)) + "/Slide" + str(i+1) + ".jpg")
                filterData = (
                    PropertyValue("PixelWidth",0,1280,0), 
                    PropertyValue("PixelHeight",0,720,0), 
                    PropertyValue("Quality",0,100,0)
                )
                writeJPEG = (PropertyValue("MediaType", 0, "image/jpeg",0),
                    PropertyValue("URL", 0, output_path,0),
                    PropertyValue("Overwrite", 0, True, 0),
                    PropertyValue("FilterData",0,uno.Any("[]com.sun.star.beans.PropertyValue", filterData),0)
                )

                print("exported", output_path)
                exporter.setSourceDocument(controller.getCurrentSlide())
                exporter.filter(writeJPEG)
                
Last edited by MrProgrammer on Thu May 18, 2023 1:44 am, edited 1 time in total.
LibreOffice 7.5.2.2 with Mac OS 12.4
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to export the screen while playing a presentation in Impress to an image

Post by RoryOF »

How are your animations triggered? Of what type are they?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
73_ch
Posts: 3
Joined: Tue May 09, 2023 9:21 am

Re: How to export the screen while playing a presentation in Impress to an image

Post by 73_ch »

Thanks, RoryOF

I'm using com::sun::star::presentation::XSlideShow.nextEffect() and update with com::sun::star::presentation::XSlideShow.update().

See the code in the first question for details.


The animation plays gradually on the screen, but the image exported by the exporter is the one after all the animations in the slide have played.
LibreOffice 7.5.2.2 with Mac OS 12.4
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to export the screen while playing a presentation in Impress to an image

Post by RoryOF »

Details in the API for animations for OpenOffice (probably similar for LibreOffice) are given at

https://www.openoffice.org/api/docs/com ... le-ix.html

I note there is an XAnimationListener which might give you the signal you need to handle your image export.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
73_ch
Posts: 3
Joined: Tue May 09, 2023 9:21 am

Re: How to export the screen while playing a presentation in Impress to an image

Post by 73_ch »

I found the same thing in the Libre Office API.
I will read this and try some more.

Thank you very much.
LibreOffice 7.5.2.2 with Mac OS 12.4
Post Reply