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";
40 foreach my $p ( 0 .. length($data) - 1 ) {
41 my $c = substr($data,$p,1);
43 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
44 $l = $w * 2 if $l == 0;
45 warn "# $p ZERO-to-EOL $c [$l]\n";
47 } elsif ( $c eq '!' ) {
48 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
49 $l = $w * 2 if $l == 0;
50 warn "# $p ONE-to-EOL $c [$l]\n";
52 } elsif ( $c eq ':' ) {
53 $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w;
55 } elsif ( $c eq 'z' ) {
57 } elsif ( $c ge 'g' && $c le 'y' ) {
58 $repeat += 20 * ( ord($c) - ord('f') );
59 } elsif ( $c ge 'G' && $c le 'Y' ) {
60 $repeat += ord($c) - ord('F');
61 } elsif ( $c =~ m/[0-9A-F]/i ) {
63 warn "# $p $repeat $c\n";
71 warn "ABORT: offset $p data [$c]";
72 $line = $c . substr($data,$p);
77 warn "## $repeat [$c] out = ",length($out),$/;
80 my $bitmap = pack('H*', $out);
81 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
83 my $ph = int(length($bitmap) / $w);
84 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w);
86 } elsif ( $line =~ s/^([~\^][^~\^\r\n]*)// ) {
87 my $cmd = substr($1,0,3);
88 if ( my $desc = $command->{$cmd} ) {
89 warn "ZPL: $1\t$desc\n";
91 warn "UNKNOWN: ",dump($1),$/;
93 $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n";
95 my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars
96 warn "IGNORE: ",dump($unknown);
103 ^A Scalable/Bitmapped Font
104 ^A@ Use Font Name to Call Font
106 ^B2 Interleaved 2 of 5 Bar Code
109 ^B5 Planet Code bar code
114 ^BB CODABLOCK Bar Code
115 ^BC Code 128 Bar Code (Subsets A, B, and C)
116 ^BD UPS MaxiCode Bar Code
118 ^BF Micro-PDF417 Bar Code
119 ^BI Industrial 2 of 5 Bar Codes
120 ^BJ Standard 2 of 5 Bar Code
121 ^BK ANSI Codabar Bar Code
124 ^BO Aztec Bar Code Parameters
127 ^BR RSS (Reduced Space Symbology) Bar Code
128 ^BS UPC/EAN Extensions
131 ^BX Data Matrix Bar Code
132 ^BY Bar Code Field Default
138 ^CF Change Alphanumeric Default Font
139 ^CI Change International Font
140 ^CM Change Memory Letter Designation
146 ~DB Download Bitmap Font
147 ~DE Download Encoding
149 ~DG Download Graphics
150 ~DN Abort Download Graphic
151 ~DS Download Scalable Font
152 ~DT Download TrueType Font
153 ~DU Download Unbounded TrueType Font
154 ~DY Download Graphics
155 ~EG Erase Download Graphics
157 ^FC Field Clock (for Real-Time Clock)
159 ^FH Field Hexadecimal Indicator
160 ^FM Multiple Field Origin Locations
164 ^FR Field Reverse Print
168 ^FW Field Orientation
172 ^GD Graphic Diagonal Line
177 ~HD Head Temperature Information
180 ^HH Configuration Label Return
181 ~HI Host Identification
183 ~HS Host Status Return
184 ~HU Return ZebraNet Alert Configuration
185 ^HV Host Verification
186 ^HW Host Directory List
188 ^HZ Display Description Information
194 ^JB Initialize Flash Memory
195 ~JB Reset Optional Memory
196 ~JC Set Media Sensor Calibration
197 ~JD Enable Communications Diagnostics
198 ~JE Disable Diagnostics
199 ~JF Set Battery Condition
200 ~JG Graphing Sensor Calibration
201 ^JJ Set Auxiliary Port
203 ^JM Set Dots per Millimeter
205 ~JO Head Test Non fatal
206 ~JP Pause and Cancel Format
209 ~JS Change Backfeed Sequence
210 ^JT Head Test Interval
211 ^JU Configuration Update
212 ^JW Set Ribbon Tension
213 ~JX Cancel Current Partially Input Format
214 ^JZ Reprint After Error
215 ~KB Kill Battery (Battery Discharge Mode)
216 ^KD Select Date and Time Format (for Real Time Clock)
218 ^KN Define Printer Name
222 ^LR Label Reverse Print
228 ^ML Maximum Label Length
233 ^MU Set Units of Measurement
234 ^MW Modify Head Cold Warning
236 ^NI Network ID Number
237 ~NR Set All Network Printers Transparent
238 ^NS Change Networking Settings
239 ~NT Set Currently Connected Printer Transparent
240 ^PF Slew Given Number of Dot Rows
241 ^PH Slew to Home Position
242 ~PH Slew to Home Position
243 ^PM Printing Mirror Image of Label
244 ^PO Print Orientation
245 ^PP Programmable Pause
246 ~PP Programmable Pause
249 ~PR Applicator Reprint
252 ~RO Reset Advanced Counter
253 ^SC Set Serial Communications
256 ^SF Serialization Field (with a Standard ^FD String)
257 ^SL Set Mode and Language (for Real-Time Clock)
258 ^SN Serialization Data
259 ^SO Set Offset (for Real-Time Clock)
261 ^SQ Halt ZebraNet Alert
262 ^SR Set Printhead Resistance
263 ^SS Set Media Sensors
264 ^ST Set Date and Time (for Real-Time Clock)
265 ^SX Set ZebraNet Alert
267 ~TA Tear-off Adjust Position
269 ~WC Print Configuration Label
270 ^WD Print Directory Label
272 ^XB Suppress Backfeed