Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I print an SVG, already scaled to a4 size, from the command line? I tried using lpr, but instead the printer just printed out the actual XML of the file, which isn't what I wanted.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

Inkscape can convert between various vector graphics formats, including SVG to PDF. Although it's normally a GUI application, it can run in batch mode without an X server available.

inkscape --without-gui --export-pdf=foo.pdf foo.svg
lpr foo.pdf

Or if you want to print directly:

inkscape --without-gui --export-pdf=/dev/stdout foo.svg | lpr

Another possibility is the Apache Batik library. However, although there is a command line tool based on that library, Fop, it doesn't seem to have a way to use SVG input, so you'd have to write a bit of glue code in Java.

share|improve this answer
add comment

Try to use a GUI, for example eye of gnome. Also firefox is able to open svg's and to print.
At least you can import the image to OpenOffice's Writer ;-)

share|improve this answer
    
he specifically asked for a command-line program –  penguin359 Apr 25 '11 at 17:49
add comment

SVG files, as you noted, are just xml text. Dumping that data straight to the printer is going to get you a bunch of nothing. What you need is a program that can RENDER that data. You say the file is already scaled to A4 size that's just a coordinate space for the scalable vector data. It isn't rendered.

However don't despair! There are lots of programs that can render the data from the command line and some that can even render and print all in one wack. You need to look into command line flags for some heavier weight programs that you might normally expect to get a GUI with.

For example, I know you can use LibreOffice on the command line to open and print a file or convert it to another format. There is a handy command line utility called unoconv that makes the conversion process a lot easier by simplifying all the flags you would have to send.

The Gimp also has some command line flags to open, convert, save and even print. Some of the old standbys like ImageMagick are also able to convert SVG files to rendered images at a given size. I expect other applications like Inkscape are also able to do this.

Once you have an image, it should be easy to print from the command line. If you do this often, you could write a little two line script to convert and print!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.