support for utf-8 encoding with lpr

7,214

Solution 1

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.

Solution 2

I don't know if you consider HPLIP an external dependency, but here is the official driver recommendation directly from CUPS.

CUPS Printer Driver: HP4650

and Here is the Package info in the Debian Repo:HPLIPS

As Thushi states your system doesn't know how to rasterize the document without using a tool like paps. Installing the hplip package and configuring it at http://localhost:631 to use the recommended driver will solve your issue. For more info, see the SystemPrinting entry at the DebianWiki

Share:
7,214

Related videos on Youtube

user001
Author by

user001

Updated on September 18, 2022

Comments

  • user001
    user001 over 1 year

    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).

    • Netch
      Netch almost 10 years
      I haven't deep CUPS knowledge but it definitely should include rules how to detect document type (with MIME type on output) and how to translate any for target printer, this includes rasterisation, forming Postscript or PCL file, etc. Could you please specify your printer type? Did you try a2ps? What encoding is really used on output, when you try utf-8? (I guess it's iso-8859-1)
    • Netch
      Netch almost 10 years
      Seems that applied encoding is iso-8859-1. You can easily check this using its table. Some searching suggests calling as lpr -o document-format='text/plain;charset=utf-8' will be enough to print as you want, but this doesn't change your CUPS installation default which seems obsolete.
  • user001
    user001 almost 10 years
    Thanks very much for your reply. I'm aware of paps and wanted to know if there was a possibility of native support within CUPS so that external dependencies needn't be invoked.
  • user001
    user001 over 9 years
    Thanks. I already have the latest version of HPLIP on my system. I tried to find where one can specify this in http://localhost:631 but I could not find anything about driver selection.
  • eyoung100
    eyoung100 over 9 years
    Read Section 4