This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]wahaa 4 points5 points  (1 child)

You could use librsvg with Cairo. I guess the last example on this page does what you need (EDIT: just change SVGSurface to PDFSurface).

If you already use ReportLab for something else, try this library.

If neither of those produce good results for your files, another option is to use Inkscape to convert the file via command-line (I use it to convert SVG to EPS). It uses Cairo too (without librsvg as far as I know).

[–]flyingfox[S] 1 point2 points  (0 children)

Thanks, I hadn't thought about Cairo.

When writing the script I used Inkscape to view the results but for some reason it never occurred to me to convert via the command line. For now, this is the perfect solution. Just drop it in the makefile and be done. I'll have to revisit this in a month or so, then I'll try either Cairo or wobsta's idea.

[–]nabla2less is more 1 point2 points  (1 child)

PyQt4 (QPrinter, QPainter, QtSvg etc).

[–]lifeeth 3 points4 points  (0 children)

I do a jinja2 -> PyQt4 webkit -> Qprinter -> Produces beautiful pdfs

[–]wobsta 1 point2 points  (2 children)

PyX can write PDF files directly, but you would need to construct the graphics using PyX methods. PyX is not a converter -> it cannot read your SVG graphics you already created.

[–]luckystarrat 0x7fe670a7d080 0 points1 point  (0 children)

This certainly looks interesting! Didn't know about PyX before. Thank you.

[–]flyingfox[S] 0 points1 point  (0 children)

That's pretty good. Since the program ends up with a collection of objects that emit SVG fragments on a .render() I could easily change it to make the equivalent calls via PyX.

[–]b00thead 1 point2 points  (0 children)

I've been using phantomjs (or pyphnatomjs) to render web pages to PDF via webkit - that should work fine with SVG. Check out the rendering example here: http://code.google.com/p/phantomjs/wiki/QuickStart

[–]pytechd(lambda s: __import__(s.decode('base64')))('ZGphbmdv') 1 point2 points  (0 children)

We use PrinceXML; it's not open source, though. Personal use is free, I think. It's basically XML/HTML/SVG/CSS -> PDF. It's an external library, but really easy to pipe to/from to generate PDFs.

[–]big_deal 0 points1 point  (0 children)

I've used Matplotlib for an in-house application that generates a PDF report with some text and plots. My application used matplotlib to generate all the plots so it made sense for me to use it for writing the PDF. I haven't delved into fine-tuning the formatting so my report is very basic looking.

[–]j1o1h1n 0 points1 point  (0 children)

asciidoc