Printing UTF-8 text via command line (i.e. 10.5-ready enscript for UTF-8)

Hello,

(I asked this question in the Leopard discussion section, but was advised to use this forum.)

I am using some terminal-based tools like Alpine and Vim, both with UTF-8 text encoding. Printing, however, is a problem, because the UTF-8 characters are not correctly printed. For Alpine I use enscript, but it does not support UTF-8. (Currently I convert UTF-8 to latin1 first using iconv before sending it to enscript, but special characters get lost that way.) For Vim I use CUPS-PDF, a virtual PDF printer, but also here UTF-8 characters does not make it (even though CUPS-PDF works for UTF-8 in Cocoa apps).

Paps as an alternative to enscript may work, but I don't want to spend much time currently installing all necessary libraries.

I am wondering if I can use Leopard's printing natively. *Is there a command line tool ready for OS 10.5 that accepts UTF-8 text and converts it to PS/PDF or sends it directly to a selected printer queue?*

Thanks!

PowerBook G4, Mac OS X (10.5.2)

Posted on Apr 24, 2008 11:57 PM

Reply
10 replies

Apr 26, 2008 7:58 AM in response to Hugin

I think you can use enscript for 8 bit code. You just have to set the option. if you check the users guide you may be able to use an option to honor 8 bit code. I haven't tried it, but my .enscriptrc looks like

cat .enscriptrc
#
# GNU Enscript configuration file.
#
# Author: Stanley Williams
#
# Local Version
#
# How characters greater than 127 are printed:
# 1 generate clean 7-bit code; print characters greater than 127
# in the backslash-octal notation `\xxx' (default)
# 0 generate 8-bit code
Clean7Bit: 1

# Default input encoding.
# DefaultEncoding: mac

# Default output media.
DefaultMedia: Letter

# Media definitions:
# name width height llx lly urx ury
Media: Legal 612 1008 24 24 588 984
Media: Letter 612 792 36 36 576 756

# Pass following Page Device options to the generated output.
#
# Duplex printing.
SetPageDevice: Duplex:true

Hope this helps.

Apr 28, 2008 5:46 PM in response to Hugin

Hugin wrote:
I am wondering if I can use Leopard's printing natively. *Is there a command line tool ready for OS 10.5 that accepts UTF-8 text and converts it to PS/PDF or sends it directly to a selected printer queue?*


The short answer is no. Unicode is too complicated to really make this feasible. There are lots of 3rd party solutions, from PDF converters to pap to ghostscript, but they will all involve downloading and installing software. Command line unicode printing is just not something that most people do.

If you have some idea of what kind of Unicode is in your documents, you can convert the text. I just did a test with:

iconv -f utf-8 -t iso-8859-1 features.xml | enscript


and it worked perfectly. Of course, almost all my Unicode text is just French. This would fail miserably with some of my Arabic files.

Apr 28, 2008 7:00 PM in response to etresoft

Did you read the man page for enscript? I haven't tried it but I think if you set the option for Cleanbit7 to false (0) it will print characters greater than 127.
From the manpage
Clean7Bit: bool
Specify how characters greater than 127 are printed. Value true (1) generates 7-bit clean code by escaping all characters greater than 127
to the backslash-octal notation (default). Value false (0) generates 8-bit PostScript code leaving all characters untouched.

HTH

Apr 28, 2008 9:09 PM in response to Stanley Williams

Stanley Williams wrote:
Did you read the man page for enscript?


Yes.

I haven't tried it but I think if you set the option for Cleanbit7 to false (0) it will print characters greater than 127.


But what good would that do? UTF-8 is much more than just high-order bits. Whatever is reading the UTF-8 must understand what that sequence of 8 bit characters really means. I don't think you can just throw UTF-8 into postscript like that.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Printing UTF-8 text via command line (i.e. 10.5-ready enscript for UTF-8)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.