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.
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.
Hover to File>Export>SVG. Click on Export to save PDF as SVG in Adobe.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With