Printing UTF-8 plain text

When printing plain text files, you might be confronted with all sorts of incompatibilities; This type of trouble is often referred to as 'alphabet soup'.

There is a way to avoid all this trouble;

  1. Make Unicode / UTF-8 the default characterset of all your apps, documents and systems.
  2. Don't use the build-in founts of your printer. Use the fonts installed on your computer instead.
For this I created a UTF-8 TXT printqueue;
/etc/printcap;

txt|UTF-8 txt:\
        :lp=/dev/null:\
        :sd=/var/spool/lpd/txt:\
        :if=/usr/local/bin/utxt-local
        :mx#0:\
        :sh:

This printcap entry sends the data to the script 'utxt-local';

With uniprint


#!/bin/bash

# This script converts UTF-8 txt to postscript

uniprint -printer lp -size 8 -hsize 0 -font /usr/share/fonts/truetype/freefont/FreeMono.ttf

'uniprint', which is in Debian package 'yudit', converts the text to postscript using a True Type Font. This data is then send to the postscript queue (on this system 'lp' is the postscript queue).

You can use any (monospaced) True Type Font for this;


uniprint -printer lj -size 8 -hsize 0 -font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf

You can even specify more then one font, creating a virtual font;

uniprint -printer lp -size 8 -hsize 0 \
        -font /path/to/1st-font.ttf \
        -font /path/to/2nd-font.ttf

See 'man uniprint' for more info.

With paps

The same can be done with paps;

#!/bin/bash

# This script converts UTF-8 txt to postscript

paps | lpr

This setup does not depend on gs fonts, the printer's build-in fonts or the printer's default character set.