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),$/;
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) ) {
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]/ ) {
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";
95 ^A Scalable/Bitmapped Font
96 ^A@ Use Font Name to Call Font
98 ^B2 Interleaved 2 of 5 Bar Code
101 ^B5 Planet Code bar code
106 ^BB CODABLOCK Bar Code
107 ^BC Code 128 Bar Code (Subsets A, B, and C)
108 ^BD UPS MaxiCode Bar Code
110 ^BF Micro-PDF417 Bar Code
111 ^BI Industrial 2 of 5 Bar Codes
112 ^BJ Standard 2 of 5 Bar Code
113 ^BK ANSI Codabar Bar Code
116 ^BO Aztec Bar Code Parameters
119 ^BR RSS (Reduced Space Symbology) Bar Code
120 ^BS UPC/EAN Extensions
123 ^BX Data Matrix Bar Code
124 ^BY Bar Code Field Default
130 ^CF Change Alphanumeric Default Font
131 ^CI Change International Font
132 ^CM Change Memory Letter Designation
138 ~DB Download Bitmap Font
139 ~DE Download Encoding
141 ~DG Download Graphics
142 ~DN Abort Download Graphic
143 ~DS Download Scalable Font
144 ~DT Download TrueType Font
145 ~DU Download Unbounded TrueType Font
146 ~DY Download Graphics
147 ~EG Erase Download Graphics
149 ^FC Field Clock (for Real-Time Clock)
151 ^FH Field Hexadecimal Indicator
152 ^FM Multiple Field Origin Locations
156 ^FR Field Reverse Print
160 ^FW Field Orientation
164 ^GD Graphic Diagonal Line
169 ~HD Head Temperature Information
172 ^HH Configuration Label Return
173 ~HI Host Identification
175 ~HS Host Status Return
176 ~HU Return ZebraNet Alert Configuration
177 ^HV Host Verification
178 ^HW Host Directory List
180 ^HZ Display Description Information
186 ^JB Initialize Flash Memory
187 ~JB Reset Optional Memory
188 ~JC Set Media Sensor Calibration
189 ~JD Enable Communications Diagnostics
190 ~JE Disable Diagnostics
191 ~JF Set Battery Condition
192 ~JG Graphing Sensor Calibration
193 ^JJ Set Auxiliary Port
195 ^JM Set Dots per Millimeter
197 ~JO Head Test Non fatal
198 ~JP Pause and Cancel Format
201 ~JS Change Backfeed Sequence
202 ^JT Head Test Interval
203 ^JU Configuration Update
204 ^JW Set Ribbon Tension
205 ~JX Cancel Current Partially Input Format
206 ^JZ Reprint After Error
207 ~KB Kill Battery (Battery Discharge Mode)
208 ^KD Select Date and Time Format (for Real Time Clock)
210 ^KN Define Printer Name
214 ^LR Label Reverse Print
220 ^ML Maximum Label Length
225 ^MU Set Units of Measurement
226 ^MW Modify Head Cold Warning
228 ^NI Network ID Number
229 ~NR Set All Network Printers Transparent
230 ^NS Change Networking Settings
231 ~NT Set Currently Connected Printer Transparent
232 ^PF Slew Given Number of Dot Rows
233 ^PH Slew to Home Position
234 ~PH Slew to Home Position
235 ^PM Printing Mirror Image of Label
236 ^PO Print Orientation
237 ^PP Programmable Pause
238 ~PP Programmable Pause
241 ~PR Applicator Reprint
244 ~RO Reset Advanced Counter
245 ^SC Set Serial Communications
248 ^SF Serialization Field (with a Standard ^FD String)
249 ^SL Set Mode and Language (for Real-Time Clock)
250 ^SN Serialization Data
251 ^SO Set Offset (for Real-Time Clock)
253 ^SQ Halt ZebraNet Alert
254 ^SR Set Printhead Resistance
255 ^SS Set Media Sensors
256 ^ST Set Date and Time (for Real-Time Clock)
257 ^SX Set ZebraNet Alert
259 ~TA Tear-off Adjust Position
261 ~WC Print Configuration Label
262 ^WD Print Directory Label
264 ^XB Suppress Backfeed