[Python] Python to Powerpoint: Export svg to a pptx file

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I was experimenting with the python-pptx library to automate the process of adding images to my presentations. I used code such as:

    from pptx import Presentation
    import os

    prs = Presentation()
    slide = prs.slides.add_slide(prs.slide_layouts[8])
    placeholder = slide.placeholders[1]
    picture = placeholder.insert_picture('pie.png')
    prs.save("ESEMPIO.pptx")


    This works just fine, but it was noted that when zooming in the pie chart contained in pie.png becomes quite pixelated. Someone suggested to use SVG format, so I saved the image as an SVG (unfortunately, I can't seem to add the SVG file here). Now, if I try to do:

    from pptx import Presentation
    import os

    prs = Presentation()
    slide = prs.slides.add_slide(prs.slide_layouts[8])
    placeholder = slide.placeholders[1]
    picture = placeholder.insert_picture('pie.svg')
    prs.save("ESEMPIO.pptx")


    I get the following error: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f38da87c350>, which I guess is because it does not like the SVG format. Is there any workaround to get an SVG into a PowerPoint presentation?

    PNG pie chart

    Continue reading...

Compartilhe esta Página