Wednesday, September 25, 2013

Server Side Image Generation from SVG

With SVG gaining so much traction lately many people are using that as a de-facto rendering technology in HTML world. This allows you to create awesome graphs and charts to visualize data using libraries like d3. 

There's one little problem which keeps you awake though and that is the fact that sometimes there are requirements to send the same graphics in and email as a image or a pdf and that becomes impossible because of the fact that there are no headless webkits available on the server side to do the rendering and convert them to image. Faced with this problem I explored a few options. The path I chose is 

1) Use EnvJS as a server side DOM.
2) Using EnvJS create a Batik SVGDOM everytime you encounter a SVG Element. 
3) Use Rhino to host EnvJS (the server is a java server)
4) Use Batik to convert the Batik SVGDOM into an image.

And it works just fine.. 

Happy Coding!!