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, $total_bytes, $row_bytes ) = split(/,/,$2,4);
32 warn "# ~DG$1 => [$name] $total_bytes bytes $row_bytes in row\n";
36 my $w = $row_bytes * 2; # hex digits
41 foreach my $p ( 0 .. length($data) - 1 ) {
42 my $c = substr($data,$p,1);
44 my $l = $w - ( length($out) % $w );
46 warn "# $p ZERO-to-EOL $c [$l]\n";
48 } elsif ( $c eq '!' ) {
49 my $l = $w - ( length($out) % $w );
51 warn "# $p ONE-to-EOL $c [$l]\n";
53 } elsif ( $c eq ':' ) {
54 # $out .= length($out) > $w ? substr($out,-$w) : "0" x $w;
55 $out .= substr($out,-$w);
56 warn "# $p repeat last line\n";
57 } elsif ( $c eq 'z' ) {
59 } elsif ( $c ge 'g' && $c le 'y' ) {
60 $repeat += 20 * ( ord($c) - ord('f') );
61 } elsif ( $c ge 'G' && $c le 'Y' ) {
62 $repeat += ord($c) - ord('F');
63 } elsif ( $c =~ m/[0-9A-F]/i ) {
65 warn "# $p $repeat $c\n";
73 warn "ABORT: offset $p data [$c]";
74 $line = $c . substr($data,$p);
79 warn "## $repeat [$c] out = ",length($out),$/;
82 my $bitmap = pack('H*', $out);
83 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
84 my $pw = $row_bytes * 8;
85 my $ph = int(length($bitmap) / $row_bytes);
86 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$row_bytes);
88 } elsif ( $line =~ s/^([~\^][^~\^\r\n]*)// ) {
89 my $cmd = substr($1,0,3);
90 if ( my $desc = $command->{$cmd} ) {
91 warn "ZPL: $1\t$desc\n";
93 warn "UNKNOWN: ",dump($1),$/;
95 $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n";
97 my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars
98 warn "IGNORE: ",dump($unknown);
105 ^A Scalable/Bitmapped Font
106 ^A@ Use Font Name to Call Font
108 ^B2 Interleaved 2 of 5 Bar Code
111 ^B5 Planet Code bar code
116 ^BB CODABLOCK Bar Code
117 ^BC Code 128 Bar Code (Subsets A, B, and C)
118 ^BD UPS MaxiCode Bar Code
120 ^BF Micro-PDF417 Bar Code
121 ^BI Industrial 2 of 5 Bar Codes
122 ^BJ Standard 2 of 5 Bar Code
123 ^BK ANSI Codabar Bar Code
126 ^BO Aztec Bar Code Parameters
129 ^BR RSS (Reduced Space Symbology) Bar Code
130 ^BS UPC/EAN Extensions
133 ^BX Data Matrix Bar Code
134 ^BY Bar Code Field Default
140 ^CF Change Alphanumeric Default Font
141 ^CI Change International Font
142 ^CM Change Memory Letter Designation
148 ~DB Download Bitmap Font
149 ~DE Download Encoding
151 ~DG Download Graphics
152 ~DN Abort Download Graphic
153 ~DS Download Scalable Font
154 ~DT Download TrueType Font
155 ~DU Download Unbounded TrueType Font
156 ~DY Download Graphics
157 ~EG Erase Download Graphics
159 ^FC Field Clock (for Real-Time Clock)
161 ^FH Field Hexadecimal Indicator
162 ^FM Multiple Field Origin Locations
166 ^FR Field Reverse Print
170 ^FW Field Orientation
174 ^GD Graphic Diagonal Line
179 ~HD Head Temperature Information
182 ^HH Configuration Label Return
183 ~HI Host Identification
185 ~HS Host Status Return
186 ~HU Return ZebraNet Alert Configuration
187 ^HV Host Verification
188 ^HW Host Directory List
190 ^HZ Display Description Information
196 ^JB Initialize Flash Memory
197 ~JB Reset Optional Memory
198 ~JC Set Media Sensor Calibration
199 ~JD Enable Communications Diagnostics
200 ~JE Disable Diagnostics
201 ~JF Set Battery Condition
202 ~JG Graphing Sensor Calibration
203 ^JJ Set Auxiliary Port
205 ^JM Set Dots per Millimeter
207 ~JO Head Test Non fatal
208 ~JP Pause and Cancel Format
211 ~JS Change Backfeed Sequence
212 ^JT Head Test Interval
213 ^JU Configuration Update
214 ^JW Set Ribbon Tension
215 ~JX Cancel Current Partially Input Format
216 ^JZ Reprint After Error
217 ~KB Kill Battery (Battery Discharge Mode)
218 ^KD Select Date and Time Format (for Real Time Clock)
220 ^KN Define Printer Name
224 ^LR Label Reverse Print
230 ^ML Maximum Label Length
235 ^MU Set Units of Measurement
236 ^MW Modify Head Cold Warning
238 ^NI Network ID Number
239 ~NR Set All Network Printers Transparent
240 ^NS Change Networking Settings
241 ~NT Set Currently Connected Printer Transparent
242 ^PF Slew Given Number of Dot Rows
243 ^PH Slew to Home Position
244 ~PH Slew to Home Position
245 ^PM Printing Mirror Image of Label
246 ^PO Print Orientation
247 ^PP Programmable Pause
248 ~PP Programmable Pause
251 ~PR Applicator Reprint
254 ~RO Reset Advanced Counter
255 ^SC Set Serial Communications
258 ^SF Serialization Field (with a Standard ^FD String)
259 ^SL Set Mode and Language (for Real-Time Clock)
260 ^SN Serialization Data
261 ^SO Set Offset (for Real-Time Clock)
263 ^SQ Halt ZebraNet Alert
264 ^SR Set Printhead Resistance
265 ^SS Set Media Sensors
266 ^ST Set Date and Time (for Real-Time Clock)
267 ^SX Set ZebraNet Alert
269 ~TA Tear-off Adjust Position
271 ~WC Print Configuration Label
272 ^WD Print Directory Label
274 ^XB Suppress Backfeed