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

If you just have a few images to convert you might find it easier to use some of the online converters. I tried CloudConvert and it did a very good job with half the file size of the SVG.
– Frank BreitlingJun 13 '17 at 17:28

7 Answers
7

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.

Will this convert to a cmyk color space?
– justingordonFeb 23 '14 at 4:18

3

@AyberkÖzgür That's inkscape's fault - when you save an Inkscape project, it will by default save it as a SVG, but the SVG it saves includes a bunch of nonstandard inkscape-specific data that can frequently mess up other programs. You need to export as an SVG rather than just saving as a SVG.
– AJMansfieldNov 7 '15 at 23:18

2

Might save some time searching: On Suse-Systems the package containing rsvg-convert is called rsvg-view.
– TrendfischerJan 22 '16 at 16:14

1

It worked for me and the quality of pdf is same as svg. Before this was using imagemagick to convert to pdf and the quality was poor especially for svg.
– Pratik SoniMay 26 '16 at 9:08

On OSX using Homebrew, you can install Inkscape using brew install inkscape these days. The resulting /usr/local/bin/inkscape worked for me without having to run X11.app.
– Alex SchröderDec 31 '15 at 22:27

1

Inkscape can be installed on OS X from the dmg distributed at its own website, and then called from the command line after creating two symbolic links: ln -s ~/Applications/Inkscape.app/Contents/Resources/bin/inkscape ~/bin/inkscape and similarly for inkscape-bin (assuming ~/bin is in your $PATH).
– Ioannis FilippidisDec 21 '16 at 13:08

You can use the -z (or --without-gui) flag with Inkscape to run it in batch mode only (no window will open at all).
– Artefact2Jan 6 '17 at 18:48

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.
– ptsJan 22 '12 at 20:15

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.