5 use Data::Dump qw(dump);
7 # convert Zebra label printer ZPL to pbm image
12 my ( $cmd, $desc ) = split(/\s/,$_,2);
13 $command->{$cmd} = $desc;
16 my $file = shift @ARGV || die "usage: $0 dump.zpl > dump.pbm";
18 open(my $in, '<', $file);
22 $line .= <$in> unless length $line > 3;
27 $line =~ s/[\r\n]+$// && warn "## removed CR/LF\n";
28 warn "# line ",dump($line),$/ if length($line) < 80 or $ENV{DEBUG};
29 if ( $line =~ s/~DG(\w+:)?(.+)// ) {
30 my ( $name, $t,$w ) = split(/,/,$2,4);
32 warn "# ~DG$1 => [$name] t=$t w=$w\n";
39 foreach my $p ( 0 .. length($data) - 1 ) {
40 my $c = substr($data,$p,1);
42 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
43 $l = $w * 2 if $l == 0;
44 warn "# $p ZERO-to-EOL $c [$l]\n";
46 } elsif ( $c eq '!' ) {
47 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
48 $l = $w * 2 if $l == 0;
49 warn "# $p ONE-to-EOL $c [$l]\n";
51 } elsif ( $c eq ':' ) {
52 $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w;
53 warn "# $p repeat last line\n";
54 } elsif ( $c eq 'z' ) {
56 } elsif ( $c ge 'g' && $c le 'y' ) {
57 $repeat += 20 * ( ord($c) - ord('f') );
58 } elsif ( $c ge 'G' && $c le 'Y' ) {
59 $repeat += ord($c) - ord('F');
60 } elsif ( $c =~ m/[0-9A-F]/i ) {
62 warn "# $p $repeat $c\n";
70 warn "ABORT: offset $p data [$c]";
71 $line = $c . substr($data,$p);
76 warn "## $repeat [$c] out = ",length($out),$/;
79 my $bitmap = pack('H*', $out);
80 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
82 my $ph = int(length($bitmap) / $w);
83 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w);
85 } elsif ( $line =~ s/^([~\^][^~\^\r\n]*)// ) {
86 my $cmd = substr($1,0,3);
87 if ( my $desc = $command->{$cmd} ) {
88 warn "ZPL: $1\t$desc\n";
90 warn "UNKNOWN: ",dump($1),$/;
92 $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n";
94 my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars
95 warn "IGNORE: ",dump($unknown);
102 ^A Scalable/Bitmapped Font
103 ^A@ Use Font Name to Call Font
105 ^B2 Interleaved 2 of 5 Bar Code
108 ^B5 Planet Code bar code
113 ^BB CODABLOCK Bar Code
114 ^BC Code 128 Bar Code (Subsets A, B, and C)
115 ^BD UPS MaxiCode Bar Code
117 ^BF Micro-PDF417 Bar Code
118 ^BI Industrial 2 of 5 Bar Codes
119 ^BJ Standard 2 of 5 Bar Code
120 ^BK ANSI Codabar Bar Code
123 ^BO Aztec Bar Code Parameters
126 ^BR RSS (Reduced Space Symbology) Bar Code
127 ^BS UPC/EAN Extensions
130 ^BX Data Matrix Bar Code
131 ^BY Bar Code Field Default
137 ^CF Change Alphanumeric Default Font
138 ^CI Change International Font
139 ^CM Change Memory Letter Designation
145 ~DB Download Bitmap Font
146 ~DE Download Encoding
148 ~DG Download Graphics
149 ~DN Abort Download Graphic
150 ~DS Download Scalable Font
151 ~DT Download TrueType Font
152 ~DU Download Unbounded TrueType Font
153 ~DY Download Graphics
154 ~EG Erase Download Graphics
156 ^FC Field Clock (for Real-Time Clock)
158 ^FH Field Hexadecimal Indicator
159 ^FM Multiple Field Origin Locations
163 ^FR Field Reverse Print
167 ^FW Field Orientation
171 ^GD Graphic Diagonal Line
176 ~HD Head Temperature Information
179 ^HH Configuration Label Return
180 ~HI Host Identification
182 ~HS Host Status Return
183 ~HU Return ZebraNet Alert Configuration
184 ^HV Host Verification
185 ^HW Host Directory List
187 ^HZ Display Description Information
193 ^JB Initialize Flash Memory
194 ~JB Reset Optional Memory
195 ~JC Set Media Sensor Calibration
196 ~JD Enable Communications Diagnostics
197 ~JE Disable Diagnostics
198 ~JF Set Battery Condition
199 ~JG Graphing Sensor Calibration
200 ^JJ Set Auxiliary Port
202 ^JM Set Dots per Millimeter
204 ~JO Head Test Non fatal
205 ~JP Pause and Cancel Format
208 ~JS Change Backfeed Sequence
209 ^JT Head Test Interval
210 ^JU Configuration Update
211 ^JW Set Ribbon Tension
212 ~JX Cancel Current Partially Input Format
213 ^JZ Reprint After Error
214 ~KB Kill Battery (Battery Discharge Mode)
215 ^KD Select Date and Time Format (for Real Time Clock)
217 ^KN Define Printer Name
221 ^LR Label Reverse Print
227 ^ML Maximum Label Length
232 ^MU Set Units of Measurement
233 ^MW Modify Head Cold Warning
235 ^NI Network ID Number
236 ~NR Set All Network Printers Transparent
237 ^NS Change Networking Settings
238 ~NT Set Currently Connected Printer Transparent
239 ^PF Slew Given Number of Dot Rows
240 ^PH Slew to Home Position
241 ~PH Slew to Home Position
242 ^PM Printing Mirror Image of Label
243 ^PO Print Orientation
244 ^PP Programmable Pause
245 ~PP Programmable Pause
248 ~PR Applicator Reprint
251 ~RO Reset Advanced Counter
252 ^SC Set Serial Communications
255 ^SF Serialization Field (with a Standard ^FD String)
256 ^SL Set Mode and Language (for Real-Time Clock)
257 ^SN Serialization Data
258 ^SO Set Offset (for Real-Time Clock)
260 ^SQ Halt ZebraNet Alert
261 ^SR Set Printhead Resistance
262 ^SS Set Media Sensors
263 ^ST Set Date and Time (for Real-Time Clock)
264 ^SX Set ZebraNet Alert
266 ~TA Tear-off Adjust Position
268 ~WC Print Configuration Label
269 ^WD Print Directory Label
271 ^XB Suppress Backfeed