Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download Raphael canvas as a SVG or PDF

Tags:

svg

raphael

I am using Raphael to create a dynamic visualization. Is it possible to allow the image generated on the Canvas to be downloaded as a SVG/PDF or another image format?

like image 745
Farhat Avatar asked May 15 '11 18:05

Farhat


2 Answers

There are pieces of information missing here, namely browser support, server-/client-side solution and whether costs are okay or not. So I'll try to give you an exhaustive answer.

For a client-side solution, you can use DocRaptor. Just feed the SVG tree to DocRaptor This works for the SVG-producing browsers (all since 2005 except for IE prior to version 9). Note that DocRaptor has a fee for converting documents into PDF. For a free server-side solution for converting an SVG tree to a PDF, I would suggest using wkhtmltopdf as proposed in this answer.

For IE6-8, which Raphaël produces VML for, you could create a PHP solution using the Vector Converter library. When the conversion from VML to SVG is finished, sent the SVG to DocRaptor (or wkhtmltopdf).

There is no free client-side VML/SVG -> PDF solution that works for VML or SVG. To build that would mean interpreting SVG and/or VML, creating a PDF from it using JavaScript (there are JS PDF library attempts), and sending it to the client using some Flash technique. I guess nobody has attempted to build that yet. I might.

like image 156
Simeon Avatar answered Sep 28 '22 02:09

Simeon


pdfkit seems to be the way to go, with using browserify to make the node code run client side. There is a nice demo here

like image 37
ejectamenta Avatar answered Sep 28 '22 02:09

ejectamenta