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 $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w;
50 } elsif ( $c eq 'z' ) {
52 } elsif ( $c ge 'g' && $c le 'y' ) {
53 $repeat += 20 * ( ord($c) - ord('f') );
54 } elsif ( $c ge 'G' && $c le 'Y' ) {
55 $repeat += ord($c) - ord('F');
56 } elsif ( $c =~ m/[0-9A-F]/i ) {
58 warn "# $p $repeat $c\n";
66 warn "ABORT: offset $p data [$c]";
67 $line = $c . substr($data,$p);
72 warn "## $repeat [$c] out = ",length($out),$/;
75 my $bitmap = pack('H*', $out);
76 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
78 my $ph = int(length($bitmap) / $w);
79 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w);
81 } elsif ( $line =~ s/^([~\^][^~\^\r\n]*)// ) {
82 my $cmd = substr($1,0,3);
83 if ( my $desc = $command->{$cmd} ) {
84 warn "ZPL: $1\t$desc\n";
86 warn "UNKNOWN: ",dump($1),$/;
88 $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n";
90 my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars
91 warn "IGNORE: ",dump($unknown);
98 ^A Scalable/Bitmapped Font
99 ^A@ Use Font Name to Call Font
101 ^B2 Interleaved 2 of 5 Bar Code
104 ^B5 Planet Code bar code
109 ^BB CODABLOCK Bar Code
110 ^BC Code 128 Bar Code (Subsets A, B, and C)
111 ^BD UPS MaxiCode Bar Code
113 ^BF Micro-PDF417 Bar Code
114 ^BI Industrial 2 of 5 Bar Codes
115 ^BJ Standard 2 of 5 Bar Code
116 ^BK ANSI Codabar Bar Code
119 ^BO Aztec Bar Code Parameters
122 ^BR RSS (Reduced Space Symbology) Bar Code
123 ^BS UPC/EAN Extensions
126 ^BX Data Matrix Bar Code
127 ^BY Bar Code Field Default
133 ^CF Change Alphanumeric Default Font
134 ^CI Change International Font
135 ^CM Change Memory Letter Designation
141 ~DB Download Bitmap Font
142 ~DE Download Encoding
144 ~DG Download Graphics
145 ~DN Abort Download Graphic
146 ~DS Download Scalable Font
147 ~DT Download TrueType Font
148 ~DU Download Unbounded TrueType Font
149 ~DY Download Graphics
150 ~EG Erase Download Graphics
152 ^FC Field Clock (for Real-Time Clock)
154 ^FH Field Hexadecimal Indicator
155 ^FM Multiple Field Origin Locations
159 ^FR Field Reverse Print
163 ^FW Field Orientation
167 ^GD Graphic Diagonal Line
172 ~HD Head Temperature Information
175 ^HH Configuration Label Return
176 ~HI Host Identification
178 ~HS Host Status Return
179 ~HU Return ZebraNet Alert Configuration
180 ^HV Host Verification
181 ^HW Host Directory List
183 ^HZ Display Description Information
189 ^JB Initialize Flash Memory
190 ~JB Reset Optional Memory
191 ~JC Set Media Sensor Calibration
192 ~JD Enable Communications Diagnostics
193 ~JE Disable Diagnostics
194 ~JF Set Battery Condition
195 ~JG Graphing Sensor Calibration
196 ^JJ Set Auxiliary Port
198 ^JM Set Dots per Millimeter
200 ~JO Head Test Non fatal
201 ~JP Pause and Cancel Format
204 ~JS Change Backfeed Sequence
205 ^JT Head Test Interval
206 ^JU Configuration Update
207 ^JW Set Ribbon Tension
208 ~JX Cancel Current Partially Input Format
209 ^JZ Reprint After Error
210 ~KB Kill Battery (Battery Discharge Mode)
211 ^KD Select Date and Time Format (for Real Time Clock)
213 ^KN Define Printer Name
217 ^LR Label Reverse Print
223 ^ML Maximum Label Length
228 ^MU Set Units of Measurement
229 ^MW Modify Head Cold Warning
231 ^NI Network ID Number
232 ~NR Set All Network Printers Transparent
233 ^NS Change Networking Settings
234 ~NT Set Currently Connected Printer Transparent
235 ^PF Slew Given Number of Dot Rows
236 ^PH Slew to Home Position
237 ~PH Slew to Home Position
238 ^PM Printing Mirror Image of Label
239 ^PO Print Orientation
240 ^PP Programmable Pause
241 ~PP Programmable Pause
244 ~PR Applicator Reprint
247 ~RO Reset Advanced Counter
248 ^SC Set Serial Communications
251 ^SF Serialization Field (with a Standard ^FD String)
252 ^SL Set Mode and Language (for Real-Time Clock)
253 ^SN Serialization Data
254 ^SO Set Offset (for Real-Time Clock)
256 ^SQ Halt ZebraNet Alert
257 ^SR Set Printhead Resistance
258 ^SS Set Media Sensors
259 ^ST Set Date and Time (for Real-Time Clock)
260 ^SX Set ZebraNet Alert
262 ~TA Tear-off Adjust Position
264 ~WC Print Configuration Label
265 ^WD Print Directory Label
267 ^XB Suppress Backfeed