jhasting has asked for the wisdom of the Perl Monks concerning the following question:

Sorry if this prints twice, I neglected to login prior to submitting this question. I think I stopped the previous post before posting.

Hello, I have been using the Term:ANSIColor module to print in color, but I would like to print this color on a printer. A simple redirect to the printer just prints the ANSI escape code. Could someone please let me know the best way to print color.

thanks
J

open(LPR, "|lpr -P agrprt165 >/dev/null 2>&1"); open TMP, ">.tmp"; $COLOR{"0"} = "black"; $COLOR{"1"} = "red"; $COLOR{"2"} = "yellow"; $COLOR{"3"} = "green"; $COLOR{"4"} = "blue"; $COLOR{"5"} = "cyan"; $COLOR{"6"} = "magenta"; $COLOR{"7"} = "white"; $ON_COLOR{"0"} = "on_black"; $ON_COLOR{"1"} = "on_red"; $ON_COLOR{"2"} = "on_yellow"; $ON_COLOR{"3"} = "on_green"; $ON_COLOR{"4"} = "on_blue"; $ON_COLOR{"5"} = "on_cyan"; $ON_COLOR{"6"} = "on_magenta"; $ON_COLOR{"7"} = "on_white"; $SPECIAL{"0"} = ""; $SPECIAL{"1"} = "dark"; $SPECIAL{"2"} = "bold"; $SPECIAL{"3"} = "underline"; $SPECIAL{"4"} = "underscore"; $SPECIAL{"5"} = "blink"; $SPECIAL{"6"} = "reverse"; $SPECIAL{"7"} = "concealed"; $SY{"0"} ="A"; $SY{"1"} ="B"; $SY{"2"} ="C"; $SY{"3"} ="D"; $SY{"4"} ="E"; for ($w=0; $w<8; $w++) { for ($x=0; $x<8; $x++) { for ($y=0; $y<4; $y++) { for ($z=0; $z<5; $z++) { $tmp = "$COLOR{$x} $ON_COLOR{$w} $SPECIAL{$y}"; print colored ("$SY{$z}", $tmp); print TMP colored ("$SY{$z}", $tmp); print LPR colored ("$SY{$z}", $tmp); } print "\n"; print TMP "\n"; print LPR "\n"; } } } close TMP; close(LPR);

edited: Tue Aug 5 17:30:58 2003 by jeffa - code tags, formatting

Replies are listed 'Best First'.
Re: send color text to printer
by Aristotle (Chancellor) on Aug 05, 2003 at 17:09 UTC
    Probably your best bet is to instead produce Postscript, or maybe TeX or some other format for which there's a to-Postscript converter. For monospace output, scribbling together some Postscript to do the job should be quite simple.

    Makeshifts last the longest.

      Thanks, could you point me to an example of code, or module which produces postscript?

      thanks again
      J

      edited: Tue Aug 5 17:36:09 2003 by jeffa - removed unclosed pre tag, adding HTML formatting

        Google turns up A First Guide to PostScript as one of the first links for a query for postscript. I had a quick look, it seems like a decent intro.

        Don't fret, Postscript is both a complex graphical model and an actual complete language, which may seem intimidating at first, but you only need the very basics of that to just put some coloured text on a page.

        Makeshifts last the longest.

Re: send color text to printer
by jeffa (Bishop) on Aug 05, 2003 at 18:04 UTC
    I see no reason to store your data in hashes, especially since the keys are consecutive numbers ... try arrays:
    my @color = qw( black red yellow green blue cyan magenta white ); my @on_color = map "on_$_", @color; my @special = (undef,qw( dark bold underline underscore blink reverse concealed )); my @sy = ('a'..'e'); for my $w (0..8) { for my $x (0..8) { for my $y (0..4) { for my $z (0..5) { my $tmp = join(' ',$color[$x],$on_color[$w],$special[$y]); ... etc. } } } }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)