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

link|improve this question

52% accept rate
feedback

4 Answers

up vote 5 down vote accepted

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

link|improve this answer
3  
convert 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 Jun 29 '11 at 14:20
1  
Just to clarify for unfamiliar readers, convert is a command-line tool for ImageMagick. – Riyaah Jun 30 '11 at 19:00
feedback

Imagemagikck 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 (http://cairosvg.org/). 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 savy 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:

#!/bin/bash

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


#!/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 oft 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)

link|improve this answer
Thanks, for sure this answer deserves more and more upvotes – neurino May 12 at 21:42
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 – ki6i May 28 at 11:30
feedback

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. :-)

link|improve this answer
feedback

Inkscape does it.

Quoting from

http://how-to.wikia.com/wiki/How_to_use_Inkscape_in_commandline_mode#Exporting_SVG_to_different_formats

inkscape -f FILENAME.svg -e FILENAME.png

loads FILENAME.svg and exports it to FILENAME.png

I tried it and it works like magic.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.