implement ! fill one to end of line compression
[Printer-Zebra.git] / pbm2ZPL.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5 use Data::Dump qw(dump);
6
7 my $pnm_file = shift @ARGV || die "usage: $0 print.pnm";
8
9 open(my $fh, '<', $pnm_file);
10 my $p4 = <$fh>; chomp $p4;
11 die "no P4 header in [$p4] from $pnm_file" unless $p4 eq 'P4';
12 my $size = <$fh>; chomp $size;
13 my ( $w, $h ) = split(/ /,$size,$2);
14 warn "WARNING: width of $pnm_file not 832!\n" if $w != 832;
15 local $/ = undef;
16 my $bitmap = <$fh>;
17
18
19 print "^XA~TA000~JSN^LT18^MNW^MTD^PON^PMN^LH0,0^JMA^PR4,4^MD13^JUS^LRN^CI0^XZ";
20
21 printf "~DG000.GRF,%d,%d,\r\n", $w / 8 * $h, $w / 8;
22
23 foreach my $y ( 0 .. $h - 1 ) {
24         my $line = substr( $bitmap, $y * ( $w / 8 ), $w / 8 );
25         print unpack('H*', $line);
26 }
27
28 print "^XA\r\n^MMT\r\n^LL0328\r\n^PW831\r\n^LS0\r\n^FT0,352^XG000.GRF,1,1^FS\r\n^PQ1,0,1,Y^XZ\r\n^XA^ID000.GRF^FS^XZ";