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?

Farhat
  • 1,203
  • 2
  • 12
  • 19
  • 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. – Farhat May 16 '11 at 05:06
  • 1
    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á! – Simeon May 16 '11 at 13:29

3 Answers3

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.

Community
  • 1
  • 1
Simeon
  • 5,519
  • 3
  • 29
  • 51
  • [jspdf](https://parall.ax/products/jspdf) will create a pdf from html or through its own library library calls. BTW pdfjs is depreciated, shame because it was quite good! – ejectamenta Feb 02 '15 at 22:20
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

ejectamenta
  • 1,047
  • 17
  • 20
1

You can save as an image using canvg and canvas2image libraries

Raathigesh
  • 2,306
  • 3
  • 26
  • 32