www.flickr.com

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

12 comments:

Anonymous said...

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

smithco said...

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

abm said...

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.

smithco said...

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.

abm said...

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

smithco said...

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 :-(

smithco said...

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

Anonymous said...

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.

Anonymous said...

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

blahedo said...

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 !

Anonymous said...

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

smithco said...

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

Post a Comment