LibreOffice Impress skill for creating, editing, converting, and automating presentation workflows using the native ODP (OpenDocument Presentation) format.
Use this skill when:
soffice --impress template.odp
import uno
def create_presentation():
local_ctx = uno.getComponentContext()
resolver = local_ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", local_ctx
)
ctx = resolver.resolve(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"
)
smgr = ctx.ServiceManager
doc = smgr.createInstanceWithContext("com.sun.star.presentation.PresentationDocument", ctx)
slides = doc.getDrawPages()
slide = slides.getByIndex(0)
doc.storeToURL("file:///path/to/presentation.odp", ())
doc.close(True)
# ODP to PPTX
soffice --headless --convert-to pptx presentation.odp
# ODP to PDF
soffice --headless --convert-to pdf presentation.odp
# PPTX to ODP
soffice --headless --convert-to odp presentation.pptx
# Batch convert
for file in *.odp; do
soffice --headless --convert-to pdf "$file"
done
import subprocess
import tempfile
from pathlib import Path
def generate_from_template(template_path, content, output_path):
with tempfile.TemporaryDirectory() as tmpdir:
subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])
content_file = Path(tmpdir) / 'content.xml'
content_xml = content_file.read_text()
for key, value in content.items():
content_xml = content_xml.replace(f'${{{key}}}', str(value))
content_file.write_text(content_xml)
subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)
return output_path
soffice --headless
soffice --headless --convert-to <format> <file>
soffice --impress # Impress
pip install ezodf # ODF handling
pip install odfpy # ODF manipulation
killall soffice.bin
soffice --headless --accept="socket,host=localhost,port=8100;urp;"