Monday, August 28, 2006

Inkscape Tip: Use Inkscape on the Command-line

It turns out that Inkscape (an SVG editor) has a few useful command-line options for non-interactive use. However, these are only documented on the Inkscape website (Manpage of INKSCAPE), but not in the documentation accessible from the program.

The real gem in the command line options is are the export options. These are a command-line interface to load up an SVG file and export as another format in a non-interactive format. This allows for the inclusion of vector format conversions in scripts.

Since the well-known image conversion utility ImageMagick does not have vector-to-vector format conversions, this is a very useful tool.

Particularly, this is an issue when using Inkscape (or other tools that use SVG) to create images for LaTeX documents, where one of EPS, PDF or PNG is typically used.

To convert an SVG file to an EPS file use
inkscape -f file.svg -E file.eps
to a PDF,
inkscape -f file.svg -A file.pdf
and to a PNG,
inkscape -f file.svg -e file.png


  1. Saldy, -P is for PS export, not PDF. I did not find a command-line option for PDF export yet.

  2. Thanks for the correction, I guess I read the man page a bit quickly.

  3. I'm working on a mac and I'm pretty new to inkscape. I'd like to do some exporting via the command line, but I must not understand where to enter commands. Any help? The man page is down.

  4. It should work from any shell you have provided that inkscape is in you path. I don't have a Mac now, but as my new MacBook should arrive in a few days, I'll be able to give you a better answer soon.

  5. OK, so how do I make sure inkscape is in my path?

  6. Now that I have my spiffy new MacBook, I've installed Inkscape and done a bit of testing.

    So far, it looks like command-line use of Inkscape on OS X is broken with version 0.45.

    I'll see if I can find a solution, but the fix may require getting into the source code and writing a couple patches. I'll try to book an evening next week to work on this.

    Blech :-(

  7. And for anonymous, it looks like -A has been added for command-line PDF export.

  8. I installed Inkscape n Mac OS X on Intel from the Inkscape website. This works:

    /Applications/Inkscape.app/Content/Resources/bin/inkscape -D -e output.png input.svg

    Now I just need to work out how to pipe that to ImageMagick convert so I can export GIF.

  9. Use -A or --export-pdf to export to PDF.

  10. Command-line use is still broken because it relies on being called with exactly that invocation—if I put a symlink in /usr/local/bin, it searches for its support files in /usr/local rather than in its own Resources directory. If I work around this by creating symlinks for inkscape-bin and the two directories in etc, then I get a dylib error that is looking for something in /Users/mjwybrow !

  11. Yes, just like anonymous said...
    Use -A or --export-pdf to export to PDF.

    And please update your blog, man, you've known the error for two years and people are actually reading it, because you're the first hit for google search 'inkscape commandline'.

  12. The correction's been made after Mr. Anonymous's insistence.

  13. If you simply linked
    $ sudo ln -s /Applications/Inkscape.app/Contents/Resources/bin/inkscape /usr/local/bin
    the "dirname $0" command will find /usr/local/bin/inkscape and not the real one.

    One way is to use dirname $(readlink $0) and thus to patch inkscape script (0.48) with:

    #CWD="`(cd \"\`dirname \\\"$0\\\"\`\"; echo \"$PWD\")`"
    CWD="`(cd \"\`dirname $(readlink \\\"$0\\\")\`\"; echo \"$PWD\")`"

    Commands like
    $ inkscape -z -D --file=image.svg --export-pdf=image-new.pdf --export-latex
    will work.
    More sophisticated commands may not work.

  14. Thanks a really useful post, and it seems to come up top on Google for a variety of searches. It could be worth adding a warning that exporting, say to pdf, via the command line may behave differently from doing it within the GUI. For instance I had to add the flag -D, which changed the export area to the drawing rather than the page.

    Although maybe a change to the post isn't necessary as you do link to the manpage which is very descriptive.

  15. Thanks! Worked like a charm.