Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I convert and SVG (containing a a few words of latin text and some simple vector graphics) to a PDF on Linux?

I tried Inkscape 0.47 on Ubuntu Lucid, but it moves some sub-graphics randomly, and it makes some lines shorter in the output PDF. So it's output is useless, because the graphics looks completely different.

I tried opening the SVG in Google Chrome 16 and printing it to PDF, but it distorts all the colors, and it also removes some elements. (The SVG appears fine on screen, but it's already bad in the print preview and the generated PDF is also bad.)

I don't want to rasterize or render the SVG. A solution which converts the SVG to a bitmap image and then creates a PDF with the image embedded is not an answer to my question. (FYI Inscape 0.47 renders the text is a very ugly way, without antialiasing, when rendering to PNG.)

What other options do I have?

share|improve this question

5 Answers 5

I have used CairoSVG successfully on OSX and Ubuntu.

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

CairoSVG Documentation

share|improve this answer
up vote 46 down vote accepted

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.

share|improve this answer
That's a lot of dependencies I'm seeing here: cairo, libgphoto, gtk3, libsane...Oh well, if it does the job... –  ShiDoiSi Apr 16 '13 at 15:47
Will this convert to a cmyk color space? –  justingordon Feb 23 '14 at 4:18
justingordon: I don't know, you can ask this as a separate StackOverflow question. –  pts Feb 23 '14 at 4:53
NOT TRUE! First line of "man rsvg-convert": "turn SVG files into raster images.". Misleading, it DOES rasterization, -1! –  peterh Jul 9 '14 at 11:03
@PeterHorvath: Thanks for the feedback. I've changed the sentence to: rsvg-convert -f pdf doesn't rasterize the SVG. This is true now. Please reconsider your downvote. The first line of the man page (turn SVG files into raster images) is inaccurate, it doesn't apply to rsvg-convert -f pdf. –  pts Jul 9 '14 at 21:30

http://superuser.com/a/79064/19956 mentions gsvg, part of GhostPDL.

I've tried gsvg ghostpdl-9.06 on Ubuntu Lucid, but it failed for two SVGs generated by Inkscape. One SVG had text in it, the other had only vector graphics. It also failed for simple graphics without Inkscape extensions or clip-path. So I don't consider gsvg a usable SVG-to-PDF converter.

share|improve this answer

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
share|improve this answer
Unfortunately this doesn’t seem to work on OS X. Still, nice answer. –  Konrad Rudolph Nov 26 '13 at 23:12
The OP specified that Inkscape had rendering bugs; this matches my experience. –  Dylan Thurston Oct 22 '14 at 17:17

I get good results from printing from Inkscape (0.47 too) to PDF, and for saving as PDF (but slightly different), but this might depend on the graphic at hand.

An alternative with lower resolution (I did not try any switches to improve it) is

 convert file.svgz file.pdf 

convert is part of the ImageMagick package. Rasterizer is another program:

 rasterizer -m application/pdf file.svgz -d file.pdf 

To find out, which programs which handle svgs are installed on your system, just try

 apropos -s 1 svg

The manpage for these programs should explain, wether the program is useful for converting the svg to pdf.

share|improve this answer
Thank you for your suggestions. FYI convert is not an answer to the original question, because convert rasterizes the SVG to a bitmap image, and the original question was looking for a solution which doesn't do that. –  pts Jan 22 '12 at 20:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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