0

I am trying to convert an SVG file to PDF in python using the svglib and reportlab packages. Here is the SVG file.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="blue" />
</svg>

Here is the code I am using to convert (got this from svglib webpage).

>>> from svglib.svglib import svg2rlg
>>> from reportlab.graphics import renderPDF
>>> drawing = svg2rlg("file.svg")
>>> renderPDF.drawToFile(drawing, "file.pdf")

The code runs fine without any error or exception but the file.pdf thus generated is a blank file. I mean that when I open this PDF file I see nothing but only white background page with nothing on it.

Where am I going wrong ?

1
  • Don't post here just because you're banned on SO May 15, 2013 at 18:28

1 Answer 1

3

If you make that last line:

renderPDF.drawToFile(drawing, "file.pdf", autoSize=0)

you will get a nice blue circle on your page. The normal parameter value for autoSize is 1 which results in the PDF being the same size as the drawing.

The problem is with your svg file having no size parameters. You can e.g. change the svg openining tag to:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="1000px" width="1000px">

to get a similar (visible) result without using autoSize=0

Not the answer you're looking for? Browse other questions tagged .