free linux command line tool to convert SVG to PDF and/or some commonly-used bitmap format?

17

6

Is there a free linux command line tool to convert SVG to PDF and/or some commonly-used bitmap format (for example PNG)?

user50105

Posted 2011-06-29T05:06:50.417

Reputation:

2mogrify -format pdf -- *.svg – Yrogirg – 2013-10-06T06:44:24.333

Answers

25

Imagemagick is great when rasterized (pixelated) output is what you want (or is at least acceptable), but is a bad choice otherwise, since it effectively embeds in the pdf a rasterized version of whatever you are trying to convert. The whole point of svg/pdf is that it can be vectorized, thereby smaller in size, while remaining smooth at any resolution.

So, I would definitely recommend using either Inkscape or CarioSVG. The latter has several command line utilities precisely for this purpose (svg2pdf, svg2ps and svg2png). The only hitch is that it is basically just a python egg, so if you don't have a python environment set up and aren't savvy enough (or don't care enough) to set one up, then that option is a no go. I tried myself, but had problems setting up the required libcairo (not that I tried too hard).

Inkscape is awesome, but the cli is a little clunky if you want just a quick little command to do all the work for you. I put together a couple of little scripts for taking care of this all for me:

svg2pdf

#!/bin/bash

for i in $@; do
  inkscape --without-gui --export-pdf="$(basename $i .svg).pdf" $i
done

svg2png

#!/bin/bash

for i in $@; do
  inkscape --without-gui --export-png="$(basename $i .svg).png" $i
done

Put the first one in ~/bin/svg2pdf and the latter in ~/bin/svg2png, run chmod +x on both of them to make them executable, and boom! You have a quick and easy shortcut for these often wanted operations that doesn't require you to think or remember how Inkscape's CLI works. (Obviously you need Inkscape installed before this will work)

metasoarous

Posted 2011-06-29T05:06:50.417

Reputation: 518

I did just one fast performance test with imagemagick and inkscape with generation of ten pdfs and imagemagick is 5.77 times faster. time for i in {1..10}; do time inkscape --without-gui -f "drawing.svg" --export-pdf="drawing$i.pdf"; done; real 0m2.192s time for i in {1..10}; do convert drawing.svg drawing$i$i$i.pdf; done; real 0m0.381s – None – 2012-05-28T11:30:47.350

6It may be faster, but you're loosing the vector nature of the graphic, so it's probably also 10 times larger (although I would love to have you correct me if I'm wrong). The reason it takes longer is because it is doing actual vector manipulations, which is a lot more complex than rasterizing (which is basically equivalent to rendering). – metasoarous – 2012-06-08T16:12:22.397

7

There's Image Magick, and Inkscape also has command line tools.

Erika

Posted 2011-06-29T05:06:50.417

Reputation: 576

2and one more clarification: if you use convert, you will switch from vector to raster and lose the ability to scale the image. in my book, it's inkscape that wins. it just depends on what you need. – nsheff – 2014-07-21T07:35:14.037

3convert wins by far. It is even able to convert to and from esoteric formats you didn't even know existed, and apply more effects to them then you'll ever need. – new123456 – 2011-06-29T14:20:40.403

3Just to clarify for unfamiliar readers, convert is a command-line tool for ImageMagick. – Erika – 2011-06-30T19:00:31.530

6

Inkscape

To PDF:

inkscape -A a.pdf a.svg

to PNG:

inkscape -e a.png a.svg

Found at man inkscape and How to use Inkscape in commandline mode

Ciro Santilli 新疆改造中心法轮功六四事件

Posted 2011-06-29T05:06:50.417

Reputation: 5 621

To add: -e is for PNG; use -A for PDF – nsheff – 2014-07-21T07:38:29.753

0

as I know, there is a way to operate Inkscape via cmd - I already used something similar for batch export PNG thumbnails from my huge SVG collection. As Inkscape also supports PDF export via Cairo, it should be possible to export PDF too. I would ask on some Inkscape forum. :-)

Juhele

Posted 2011-06-29T05:06:50.417

Reputation: 2 297