Created
September 22, 2020 16:28
-
-
Save johnjohnlin/92698b1947bd25969285eaf3cf530e49 to your computer and use it in GitHub Desktop.
A simple script converting an odg file into individual SVG pages, works for libreoffice 7.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# usage: if you have an xxx.odg, then execute `./odg2svgs.py xxx` | |
import sys | |
import subprocess | |
import xml.etree.ElementTree as ET | |
kBASENAME = sys.argv[1] | |
subprocess.run(["libreoffice", "--draw", "--headless", "--convert-to", "svg", kBASENAME+".odg"], check=True) | |
tree = ET.parse(kBASENAME + ".svg") | |
root = tree.getroot() | |
pages_top = root.find('.//{http://www.w3.org/2000/svg}g[@class="SlideGroup"]') | |
pages = list(pages_top) | |
for page in pages: | |
pages_top.remove(page) | |
for pagenum, page in enumerate(pages): | |
pages_top.append(page) | |
tree.write(f"{kBASENAME}-{pagenum:04d}.svg") | |
pages_top.remove(page) | |
subprocess.run(["rm", kBASENAME+".svg"], check=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment