Download Raphael canvas as a SVG or PDF
Asked Answered
A

3

6

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?

Anchorage answered 15/5, 2011 at 18:25 Comment(2)
In response to the first comment. I am targeting all standards-compliant browsers. Would prefer a free solution ideally and no Flash. Server-side solutions are fine.Anchorage
The first answer supplies you with a solution for what you are asking: Use Vector Converter to get VML as SVG (this step is just for IE6-8). Then use wkhtmltopdf to process the SVG into a PDF document. Return it as application/pdf and voilá!Oporto
O
9

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.

Oporto answered 15/5, 2011 at 20:33 Comment(1)
jspdf will create a pdf from html or through its own library library calls. BTW pdfjs is depreciated, shame because it was quite good!Monge
M
5

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

Monge answered 2/2, 2015 at 22:39 Comment(0)
L
1

You can save as an image using canvg and canvas2image libraries

Landfall answered 19/1, 2012 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.