Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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" 

<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" />

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 ?

share|improve this question

closed as off topic by Michael Mrozek May 15 '13 at 18:27

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Don't post here just because you're banned on SO – Michael Mrozek May 15 '13 at 18:28
up vote 3 down vote accepted

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

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.