Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating PDFs from SVG input

I am trying to generate a PDF from a SVG input file with Python in a Django application.

I have already found 2 working solutions: cairo+rsvg and imagemagick but they both have one problem: They have some strange dependencies that I do not want to install on a server, for example DBUS and GTK.

So I am asking for another method for generating a PDF from SVG without having to install all these dependencies on a server.

like image 640
Julian Avatar asked Apr 29 '11 18:04

Julian


People also ask

How do I save an SVG as a PDF?

Hover to File>Export>SVG. Click on Export to save PDF as SVG in Adobe.

Is SVG a PDF vector File?

SVG is a vector graphic image file extension that contains scalable images. This XML based file extension supports animation that can contains vector graphics, raster graphics, and text. It uses lossless data compression algorithm to contain data. It can be edited drawing software as well as text editors also.

Does PDF use SVG?

As far as I know, Acrobat does not recognise SVG directly. You would have to convert to a friendlier format (PNG or JPG) and in Acrobat X, open the 'Tools' panel then expand the Contents pane. Select 'Edit Object'.


1 Answers

Have you considered svglib?

It looks quite promising, especially as reportlab is the featured pdf tool in Django's docs.

from svglib.svglib import svg2rlg from reportlab.graphics import renderPDF  drawing = svg2rlg("file.svg") renderPDF.drawToFile(drawing, "file.pdf") 
like image 90
arie Avatar answered Sep 24 '22 07:09

arie