Exporting a SVG image file to Word


I’m trying to export a svg image to microsoft Word using the WordFileImage.

WordFileImage works with a _io.BufferedReader file from path. But when i generate a _io.BufferedReader from svg it won’t work. Returning viktor.errors.InternalError: An unexpected error occurred.

I hope someone can clarify this for me

Using same file format working in the 1st case, not the 2nd.

docs description of neccesary file format:

Hi Sven,

I have quickly checked this and the image processing library we use (Pillow) does not support SVG. This is not well documented on our side, we will have to update this.

A solution would be to convert your svg to png, I think there should be libraries out there that may help you. Another possibility would be for gef_visualization to provide a PNG export as well, however this is not yet possible.


1 Like

Hi @khameeteman,

Thanks for your quick reply!

The world file templater seems to have problems with any SVG to PNG converter package. We’ve installed several packages in which we tried to convert the SVG to a PNG BytesIO readable file. We succeeded in creating PNG files, images which we could open with microsoft photos. But we could not succeed in reading the “created” image in the world file tag. An converted PNG with an online tool was readable with the written code. So we are a clueless on what we can do now.

Hi Sven sorry for the delay.

I managed to successfully add an SVG with cairosvg:

from cairosvg import svg2png

image_path = Path(__file__).parent / 'test.svg'
with open(image_path) as f:
    img_data = svg2png(bytestring=f.read())
    components.append(WordFileImage(BytesIO(img_data), 'image1'))

Does this work for you?

1 Like

We already figured out a work around for the use of image’s, but i will test this at a later time.