How do I convert an SVG to a PDF on Linux

rsvg-convert did the trick for the SVG I wanted to convert:

$ sudo apt-get install librsvg2-bin
$ rsvg-convert -f pdf -o t.pdf t.svg

rsvg-convert -f pdf doesn't rasterize the SVG, and it embeds and subsets fonts (at least it has embedded the used characters of the Arial font). Sometimes font embedding fails (e.g. for the LMRoman17 font), and the whole font file gets copied to the generated PDF.

Dependencies on Ubuntu Lucid:

  • libcairo.so.2
  • libgobject-2.0.so.0
  • libgthread-2.0.so.0
  • libglib-2.0.so.0
  • librsvg-2.so.2
  • libpthread.so.0
  • libc.so.6

By default, libcairo needs libX11, so rsvg-convert may be hard to install to a headless system.

Note: The man page of rsvg-convert states that the tool always rasterizes, but this isn't true. The manual is simply obsolete. Sometimes your svg generating tool can partially rasterize the svg image, which can also mislead you.


This works on Ubuntu Lucid:

$ sudo apt-get install inkscape
$ inkscape t.svg --export-pdf=t.pdf

The command-line Inkscape invocation above works even in headless mode, without a GUI (DISPLAY=). However, installing Inscape installs lots of dependencies, including X11.

Please note that the exit status of Inskscape is always 0, even if an error occurs -- so watch out for its stderr.

There is also inkscape --shell, suitable for converting many documents in a batch. This avoids the slow Inkscape startup time for each file:

$ (echo t.svg --export-pdf=t.pdf;
   echo u.svg --export-pdf=u.pdf) |
  DISPLAY= inkscape --shell

Inkscape is also useful for simplifying an SVG:

$ DISPLAY= inkscape t.svg --export-plain-svg=t.plain.svg

I have used CairoSVG successfully on OSX and Ubuntu.

pip install cairosvg
cairosvg in.svg -o out.pdf

CairoSVG Documentation