in reply to Re^3: send color text to printer
in thread send color text to printer

Thanks again for the pointer, I did attempt to use postscript previously, but my Yahoo search did not yield as productive of a guide as you pointed me to. Here is my simple, quick code to populate every cell of a page with a unique character (which is what I needed). NOTE: it produces a large file. I thought I would post if anyone was interested.
$COLOR{"0"} = "0 0 0"; $COLOR{"1"} = "0 0 1"; $COLOR{"2"} = "0 1 0"; $COLOR{"3"} = "0 1 1"; $COLOR{"4"} = "1 0 0"; $COLOR{"5"} = "1 0 1"; $COLOR{"6"} = "1 1 0"; $COLOR{"7"} = "1 1 1"; $SY{"0"} = "0"; $SY{"1"} = "1"; $SY{"2"} = "2"; $SY{"3"} = "3"; $SY{"4"} = "4"; $SY{"5"} = "5"; $SY{"6"} = "6"; $SY{"7"} = "7"; $SY{"8"} = "8"; $SY{"9"} = "9"; open OUT, ">test.ps"; print OUT "%!\n"; print OUT "72 72 scale\n"; print OUT ".25 .25 translate\n"; print OUT "/Courier findfont .095 scalefont setfont\n"; $sy1=1; $color=0; for ($y=1; $y<=148; $y++) { $sy = $sy1; $sy1++; if ($sy1 > 9) {$sy1 = 0;} for ($x=1; $x<=130; $x++) { $_x = $x*.060; $_y = $y*.070; print OUT "$COLOR{$color} setrgbcolor\n"; print OUT "$_x $_y moveto ($SY{$sy}) show\n"; $sy++; if ($sy > 9) {$sy=0;} $color++; if ($color > 7) {$color = 0;} } } print OUT "showpage\n"; close OUT; `lp test.ps`;

Replies are listed 'Best First'.
Re^5: send color text to printer
by Aristotle (Chancellor) on Aug 05, 2003 at 21:50 UTC

    Hmm.. why use a hash for keys that are just consecutive integers starting at 0? And why write to a temporary file if you can feed the external process directly? Also, Perl knows lists; use the easier to maintain for(@LIST) form of for loops when you don't have special requirements. As well, post-increments return the value a variable had before incrementing it, so you don't need to do that in two steps. Finally, your wrap-around code can be expressed much more naturally using a modulo operation.

    use strict; use warnings; my @COLOR = ( "0 0 0", "0 0 1", "0 1 0", "0 1 1", "1 0 0", "1 0 1", "1 1 0", "1 1 1", ); my $postscript = << 'END_POSTSCRIPT'; %! 72 72 scale .25 .25 translate /Courier findfont .095 scalefont setfont END_POSTSCRIPT my $sy1 = 1; my $color = 0; for my $y (1 .. 148) { my $sy = $sy1; $sy1 %= 10; for my $x (1 .. 130) { my $_x = $x * .060; my $_y = $y * .070; $postscript .= "$COLOR{$color} setrgbcolor\n"; $postscript .= "$_x $_y moveto ($sy) show\n"; $sy = ($sy + 1) % 10; $color = ($color + 1) % 8; } } open '|-', my $lp, 'lp' or die "Couldn't spawn lp: $!\n"; print $lp $postscript;

    Please use strict and warnings, until you know when you don't need to. This is not just advice to appease the theorists in the ivory tower - making your code work with them will save you many a headache. See

  • Use strict warnings and diagnostics or die
  • Use strict warnings and diagnostics
  • Use strict and warnings
  • Makeshifts last the longest.