Unable to covert svg to png using svglib

Viewed 536

When I convert svg to png I'm getting an uncomplete png file and the error. Please someone help.

from reportlab.graphics import renderPM
from svglib.svglib import svg2rlg

svg_file = 'svgfile.svg'

drawing = svg2rlg(svg_file)
renderPM.drawToFile(drawing, "new_file.png", fmt="PNG")
Can't handle color: url(#a)
Can't handle color: url(#b)
Can't handle color: url(#c)
1 Answers

Not sure if this is helpful in your case, but it answered my issue (same "Can't handle color: url(...)" message.

From the svglib PyPi documentation (https://pypi.org/project/svglib/):

color gradients are not supported (limitation of reportlab)

In my case, these colors were gradients, so I'm going to convert the svg to a png on the side, and then just embed the png image in the pdf via my Python script. Not ideally what I wanted, but this png workaround suffices for my requirements.

Related