deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
307 stars 79 forks source link

convert to pdf and png files is incorrect #360

Closed alan0526 closed 1 year ago

alan0526 commented 1 year ago

svglib==1.4.1 installed via pip. Python 3.9.2

I use svglib and reportlab to convert svg to pdf and png

Files SVG bmw logo PDF bmw logo.pdf PNG bmw logo

Code from svglib.svglib import svg2rlg from reportlab.graphics import renderPDF, renderPM

def svg2pdf(svg_path, path): drawing = svg2rlg(svg_path) renderPDF.drawToFile(drawing, path)

def svg2fmt(svg_path, path, fmt="PNG", dpi=75): drawing = svg2rlg(svg_path) renderPM.drawToFile(drawing, path, fmt=fmt, dpi=dpi)

the converted pdf and png is not correct, both of them are look different.

github-actions[bot] commented 1 year ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

claudep commented 1 year ago

The PNG renderer is known to be limited, see also #299.

Could you tell us what make you think the PDF is not correct? By the way, the method used to draw the logo is not optimal (circle with big stroke and dasharray), SVG has arcs that would be more appropriate and probably more precise.

alan0526 commented 1 year ago

I want to create a rotated bmw logo with svg, convert it to pdf, and send it to our chart supplier. it is used for camera quality test, so the accuracy is very import. But after I convert this svg to pdf, the pattern looks different. Thanks for you advice, I will try to use arcs to draw this pattern.

alan0526 commented 1 year ago

here are files base on svg arcs(path) PNG: chart SVG: chart PDF: chart.pdf

svg and pdf seems correct, but the png arcs are not very smooth, is there any setting for png generator? png dpi is set to 300

claudep commented 1 year ago

You may try the alternate PNG renderer as in https://github.com/deeplook/svglib/issues/299#issuecomment-918111040. Anyway, there is nothing svglib can do to fix that, therefore closing.