Skip to content

Converting SVG to PDF

by Ofir on November 9th, 2008

I recently had the need to dynamically create PDF files based on Adobe Illustrator (*.ai) files created by a talented artist. The application allowed the user to embed his name on the resulting pdf file, and I had to make sure the quality of the drawing wasn’t lost, since it was going to be used for printing. Therefore I turned to SVG, a wonderful XML-based file format for vector images.

XML files are relatively easy to work with on the server, so by converting the AI file to SVG I was able to edit the drawing dynamically. But it turned out converting SVG to PDF on the fly wasn’t as straightforward as I thought. Fortunately a colleague at work found out a very nice way to do it by using an application called Inkscape. It was a bit hard to get the dependencies working on the RHEL server we had, but he finally managed to get it going.

If you’re using Ubuntu, there’s nothing to worry about, Inkscape is as easy to install as running the following on your command line:

sudo apt-get install inkscape

Inkscape has an option for using it as a command-line tool, this is what you must run in order to convert SVG to PDF:

inkscape -z --file=original.svg --export-pdf=converted.pdf

For it to work properly you have to make sure you have the latest Cairo libraries installed.

Here’s an example of the result:

tiger.svg tiger.pdf

This process also embeds the necessary fonts defined in the SVG into the PDF file.

Hope this is useful to someone.

Share or bookmark this post:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

From → linux

7 Comments
  1. thx, that was useful

    using “man inkscape” I’ve learned that there are also some other useful options apart from “-z”. For example I use this function to convert all SVG files from current folder into PNG format:

    function svg2png() {
    for file in $(ls *.svg);
    do
    inkscape -D -e ${file%.svg}.png ${file} ;
    done
    }

    cheers
    Tomek

  2. Johannes permalink

    Thank you, I was looking for a SVG to PDF converter – I can now run a script to ensure all my images are up to date before compiling my latex.

  3. pianom4n permalink

    this is just what i needed to get svgs into latex. thanks!

  4. morgan permalink

    just what i was looking for – thanks!

  5. Jacob permalink

    Thanks, this just saved my day!

  6. Very useful, thanks!

    This works much much better than “saving as” PDF inside the Inkscape GUI!

  7. Great! Thanks for this trick. I work much with gnuplot and I prefer to save images in svg and export to pdf, than eps to pdf because of when export to eps with gnuplot the alineation of text and tics sometimes differt from the graphical terminal.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS