Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export SVG elements to PDF?

I have a visualization generated by d3 (a javascript visualization library similar to Protovis or Raphael, which draws stuff using SVG elements). The vis is interactive, so the user can interact with and edit it. Once the user is satisfied with his/her visualization, I would like the user to be able to export this visualization as a PDF. I've tried several HTML to PDF libraries and they don't work with SVG elements.

It is okay if the solution is either client side or server side. I'm using PHP server side but Python or Java implementations might also work.

Browser support: Ideally it would support all modern browsers, but minimally I'd like to support latest versions of both Firefox and webkit browsers.

like image 962
raviparikh Avatar asked Jan 31 '12 23:01

raviparikh


People also ask

Can you turn an SVG into a PDF?

This is what you need to do in Inkscape to convert the svg to PDF: Open Inkscape and click File->Open to load the file for conversion. Click File then Print or press Ctrl+P and in the Print window select novaPDF as the printer. Click on Print and the SVG will be saved as PDF.

How do I save an SVG as a PDF?

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

How do I export SVG files?

Export art to SVG To save your artwork artwork as SVG, choose File > Export > SVG (svg). Check Use Artboards if you'd like to export the contents of your artboards as individual SVG files. Click Export to open the SVG Options dialog.


2 Answers

I do not know of any strong PDF libraries on the client side.

A quick possible way would be to send the svg content to a server, and use something like batik for java to turn the svg to pdf and then send the response to the client again.

Here is a related SO for the converstion.

like image 61
Nicolas Modrzyk Avatar answered Oct 13 '22 10:10

Nicolas Modrzyk


There's also wkhtml2pdf, which can render anything webkit can as a PDF. If you want to render a combination of SVG and HTML, or want to have some JavaScript run before the PDF snapshot is taken, it's great for that.

  • http://code.google.com/p/wkhtmltopdf/
like image 32
peteorpeter Avatar answered Oct 13 '22 10:10

peteorpeter