Support for utf-8 encoding with lpr

character encodingcupslprunicode

While trying to send a text file to the printer via lpr from xterm, the content was corrupted beyond recognition, the cause of which was ultimately traced to the encoding of the file. If I instead process the text with iconv (e.g., iconv -f utf-8 -t ascii//TRANSLIT), then the file is printed normally. Another suggestion I came across is setting the document format (e.g., lpr -o document-format=text/utf8), but this returns the error lpr: Unsupported document-format "text/utf8". I could always alias the lpr command to include processing by iconv, but is there a more general way for native utf-8 support in the CUPS/lpr system?

Edit: My OS is Debian 8 and my window manager is openbox (no desktop environment). I can print this file without any problem from MacOS X as well as from a Debian7/Gnome3 system.

From my current system, I should point out that even after changing character encoding from UTF-8 to ASCII, the newline characters are not respected by lpr, so the lines are concatenated together and printed until the paper margin is reached. After recoding and transliteration with iconv on MacOS X, the printing still works normally (so the newline issue is also specific to my current system).

Best Answer

The same can be done with paps;

#!/bin/bash
#This script converts UTF-8 txt to postscript
paps | lpr
Sometimes you need to specify the prinqueue;

#!/bin/bash
# This script converts UTF-8 txt to postscript
paps | lpr -P lj

Paps does a much better job then cups' texttops.

Related Question