Export Draw document to SVG programmatically

Greetings everyone,

Has anyone attempted before to export a simple Draw document (lines, circle and simple text) to an SVG file programmatically? I’m searching through the API reference plus I’m looking through posts over here, as well as the OpenOffice forum and cannot get anywhere.

soffice --convert-to svg  /path/to/some/document.odg
1 Like

If you need more control for each page in document, used method storeToURL

https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1frame_1_1XStorable.html#af48930bc64a00251aa50915bf087f274

Please see a programmatic option below:

Sub exportToSVG
Dim oDoc As object: oDoc = thisComponent
Dim oDrawPages As object: oDrawPages = oDoc.getDrawPages()
Dim oDrawPage As object: oDrawPage = oDrawPages.getByIndex(0)
Dim oShape As object: oShape = oDrawPage.getByIndex(0)
Dim Args(1) As New com.sun.star.beans.PropertyValue
Dim gEF As Object: gEF = createUnoService(“com.sun.star.drawing.GraphicExportFilter”)

gEF.setSourceDocument(oShape) 'shape can be replaced by a shape group or a drawpage

Args(0).Name = “URL”
Args(0).Value = convertToURL(“c:\filename.svg”)
Args(1).Name = “MimeType”
Args(1).Value = “image/svg+xml”

gEF.filter(Args)
End Sub