4

Is it possible to print an svg file via image viewer (i.e. eye of gnome) from the command line, or by using lpr?

The underlying problem is that I have a directory with many svg files in it and want to print all of them automatically without having to individually open each file in image viewer and then print using the UI. I don't need to change any print options within eog (the defaults all work fine).

Note that the lpr command doesn't seem to help here - when applied to svg files it just prints out many pages of XML. I would be just as happy with any solution that involves getting lpr to print the image in an svg rather than the XML.

3 Answers 3

4

As you have experienced lpr will only print svg files as XML (and thus prints pages filled with text only).

However there is a very simple workaround which is to convert the svg files to something more workable such as png on the fly and then automatically print these generated files. Two steps are required:

Step 1: Install imagemagick:

sudo apt-get install imagemagick

Step 2: As long as you have lp configured correctly with a 'default' printer then run the following loop in a Terminal screen from within the directory containing your svg files:

for i in *.svg
do
convert "$i" png:- | lpr
done

Explanation:

This 'loop' accomplishes the following:

  1. Processes each svg file in turn in the directory
  2. Uses the convert utility (part of imagemagick) to produce png files from each and every svg file
  3. Passes each png file to stdout (rather than writing it permanently to disk)
  4. Prints this file using lpr

This tested perfectly on my own system and should run equally well on your system :).

2
  • Fantastic. Exactly what I was after. Thank you very much. Jun 4, 2017 at 23:36
  • @ColinTBowers Great to hear that it all worked out :)
    – andrew.46
    Jun 5, 2017 at 0:41
0

Converting to a printer-friendly vector format will yield a higher quality.

sudo apt-get install librsvg2-bin
for i in *.svg
do
rsvg-convert -f pdf "$i" | lpr
done
0

You can show all svgs in a folder by simply executing

find ~/my_folder/ -name '*.svg' -exec display "{}" \;

Therefore, you need to have imagemagick installed:

sudo apt install imagemagick

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .