I'm developing some scripts to generate SVG files and I wonder what good SVG renderers exist for Linux. I know Firefox/Chrome provide SVG support (and I have the feeling that Chrome is faster at rendering) but maybe there are other standalone SVG renderers that I'm missing. I'm aware of pySVG's existence.
By good enough I mean to cover the SVG 1.1 specification as much as possible. The reason I prefer a standalone library is that my workflow is faster, as I don't have to press F5 every time.
Qt SVG it's just 2 clicks away, if you install Qt 4.7 and select the locally installed sample project svgviewer. Just build and run to get an animated viewport:
Apache Batik is a very good collection of libraries/programs with support for a very large part of the SVG specification. It includes a stand-alone viewer/editor, and a command line rasterizer that can convert SVGs to raster image formats.
You can try the command-line app
qiv
with the-m -T
flags.I recommend WebkitGtk. This is the renderer that is used to power Safari, Chrome, and a number of other browsers. It supports rendering SVG as well as HTML.
Just
apt-get install libwebkitgt-3.0-0
. You can try it out by running/usr/lib/webkitgtk-3.0-0/libexec/GtkLauncher
.You can then use whatever language/bindings you like to build a GUI around the SVG renderer, including Python's Gtk bindings: http://www.aclevername.com/articles/python-webgui/
Here's another good article about building desktop UIs using Webkit and pygtk bindings: http://arstechnica.com/information-technology/2009/07/how-to-build-a-desktop-wysiwyg-editor-with-webkit-and-html-5/
The SVG 1.1 exported by the draw.io tool is too "modern" for correct rendering by the current Batik, Cairo, qiv, or even FireFox: it seems none of them support the <foreignObject> element. However WebKit does render it properly, so to convert SVG to high-quality images I use the "wkhtmlto..." tools from http://wkhtmltopdf.org.
wkhtmltoimage
generates output at screen resolution and its--zoom
switch scaled lines and text differently resulting in clipping (although opening the same SVG in Chrome and zooming performed correctly). So instead I'm usingwkhtmltopdf
to generate an intermediate pdf then rendering that as a high-resolution image with ghostscript:EDIT: a disadvantage of going via a Page Description Format is that the image file produced may have very large borders. You can experiment with paper sizes and layouts to minimise this or just auto-crop them off, e.g. with ImageMagick:
EDIT: FireFox 49.0.2 (Nov 2016) now renders the draw.io SVG correctly. Haven't retested Cairo or Batik. sample draw.io file