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
Saldy, -P is for PS export, not PDF. I did not find a command-line option for PDF export yet.
ReplyDeleteThanks for the correction, I guess I read the man page a bit quickly.
ReplyDeleteI'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.
ReplyDeleteIt 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.
ReplyDeleteOK, so how do I make sure inkscape is in my path?
ReplyDeleteNow that I have my spiffy new MacBook, I've installed Inkscape and done a bit of testing.
ReplyDeleteSo 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 :-(
And for anonymous, it looks like -A has been added for command-line PDF export.
ReplyDeleteI installed Inkscape n Mac OS X on Intel from the Inkscape website. This works:
ReplyDelete/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.
Use -A or --export-pdf to export to PDF.
ReplyDeleteCommand-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 !
ReplyDeleteYes, just like anonymous said...
ReplyDeleteUse -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'.
The correction's been made after Mr. Anonymous's insistence.
ReplyDeleteIf you simply linked
ReplyDelete$ 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.
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.
ReplyDeleteAlthough maybe a change to the post isn't necessary as you do link to the manpage which is very descriptive.
Thanks! Worked like a charm.
ReplyDelete