figurebelow figurebelow - 1 year ago 158
Linux Question

Good SVG renderer for Linux?

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.

Answer Source

The SVG 1.1 exported by the 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

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 using wkhtmltopdf to generate an intermediate pdf then rendering that as a high-resolution image with ghostscript:

wkhtmltopdf callbacks.svg callbacks.pdf
gs -sDEVICE=pnggray -sOutputFile=callbacks.png -dBATCH -dNOPAUSE -r900 callbacks.pdf

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:

convert callbacks.png -trim callbacks.png

EDIT: FireFox 49.0.2 (Nov 2016) now renders the SVG correctly. Haven't retested Cairo or Batik. sample file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download