1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
|
%% $Id: pst-bezier-doc.tex 104 2009-03-04 16:06:54Z herbert $
\documentclass[11pt,english,BCOR10mm,DIV12,bibliography=totoc,parskip=false,smallheadings
headexclude,footexclude,oneside]{pst-doc}
\usepackage[utf8]{inputenc}
\usepackage{pst-barcode}
\let\pstBarcodeFV\fileversion
\lstset{preset=\centering,pos=l,wide=false,vsep=5mm,language=PSTricks,%width=0.5\linewidth,
morekeywords={multidipole,parallel},basicstyle=\footnotesize\ttfamily}
%
\def\bgImage{\begin{pspicture}(1in,1in)
\psbarcode{Herbert Voss Freie Universitaet Berlin}{rows=52 columns=52}{datamatrix}
\end{pspicture}}
\begin{filecontents*}{demo.tex}
\documentclass{article}
\usepackage{pst-barcode,fancyvrb}
\begin{document}
\VerbatimInput{\jobname.tex}% test
\begin{pspicture}(2in,2in)
\psbarcode[file]{\jobname.tex}{}{qrcode}
\end{pspicture}
\end{document}
\end{filecontents*}
\begin{document}
\title{\texttt{pst-barcode}}
\subtitle{A PSTricks package for drawing bar codes; v.\pstBarcodeFV}
\author{Terry Burton \\Herbert Vo\ss}
\docauthor{Herbert Vo\ss}
\date{\today}
\maketitle
\tableofcontents
\clearpage
\begin{abstract}
\noindent
The \LPack{pstricks} related package provides (essentially) one macro
for printing barcodes. The type of the code is defined by a parameter
and passed to postscript.
%\vfill\noindent
%Thanks to: \\
% Jean-C\^ome Charpentier.
\end{abstract}
\section{Introduction}
The \LPack{pstricks} package provides (essentially) one macro
for printing barcodes. The type of the code is defined by a parameter
and passed to postscript.
To install the package put the three files in a place, where \TeX{} will search
for the files:
\bigskip\noindent
\begin{tabular}{@{} l l l @{}}\hline
\emph{name} & \emph{meaning}& \emph{target dir} \\\hline
\verb+pst-barcode.tex+ & \LaTeX\ style file -- wrapper & \verb+$LOCALTEXMF/tex/generic/pstricks/+\\
\verb+pst-barcode.sty+ & \TeX\ file -- PS interface &\verb+$LOCALTEXMF/tex/latex/pstricks/+\\
\verb+pst-barcode.pro+ & PostScript file & \verb+$LOCALTEXMF/dvips/pstricks/+ \\
\verb+pst-barcode-doc.tex+ & documentation source & \verb+$LOCALTEXMF/doc/pstricks/+\\
\verb+pst-barcode-doc.bib+ & bibliography source & \verb+$LOCALTEXMF/doc/pstricks/+\\
\verb+pst-barcode-doc.pdf+ & documentation & \verb+$LOCALTEXMF/doc/pstricks/+ \\\hline%$
\end{tabular}
\bigskip
There is only one macro \verb+\psbarcode+ with the usual PSTricks syntax
\begin{BDef}
\Lcs{psbarcode}\OptArgs\Largb{text or filename}\Largb{PS options}\Largb{barcode type}
\end{BDef}
Important is the fact, that the barcode is printed in a \TeX\ box of zero dimension.
If you want to save some space in your text, use the \Lenv{pspicture} environment
or the \Lcs{makebox} macro.
\section{The options}
\subsection{The \TeX\ options}
\begin{tabular}{@{}lll@{}}\hline
\emph{name} & \emph{default} & \emph{remarks}\\\hline
\Lkeyword{transx} & 0 & horizontal shift\\
\Lkeyword{transy} & 0 & vertical shift\\
\Lkeyword{scalex} & 1 & horizontal scaling\\
\Lkeyword{scaley} & 1 & vertical scaling\\
\Lkeyword{rotate} & 0 & rotating angle in degrees\\\hline
\Lkeyword{file} & false & load an external file for the text\\\hline
\end{tabular}
\subsection{The PostScript options}
\begin{tabularx}{\textwidth}{@{}llX@{}}\hline
\emph{name} & \emph{default} & \emph{remarks}\\\hline
\Lps{height} & 1 & dimension is inch\\
\Lps{textsize} & 10 & dimension is pt\\
\Lps{textpos} & -2 & dimension is pt; it is the shift for additional code text\\
\Lps{inkspread} & 0.15 & dimension is pt\\
\Lps{showborder} & -- & - \\
\Lps{borderwidth} & 0.5 & dimension in pt \\
\Lps{borderleft} & 10 & dimension in pt\\
\Lps{borderright} & 10 & dimension in pt\\
\Lps{bordertop} & 1 & dimension in pt\\
\Lps{borderbottom} & 1 & dimension in pt\\
\Lps{borderwidth} & 0.5 & dimension in pt\\
\Lps{width} & -- & dimension in inch\\
%
\Lps{font} & /Helvetica & must be a PostScript font\\
\Lps{includetext} & -- & enable human readable text \\
\Lps{includecheck} & -- & enable check digit \\
\Lps{includecheckintext} & -- & check digit visible in text\\
\Lps{parse} & -- & parse variable field für decimal values, like \^{}032 for space, and convert them to ASCII\\\hline
\end{tabularx}
\subsection{Examples for the TeX options}
\begin{LTXexample}[pos=t,preset=\centering,wide]
\psframebox{\begin{pspicture}(2.5,1in)
\psbarcode{01335583}{includetext}{ean8}
\end{pspicture}}\quad
\psframebox{\begin{pspicture}(-2.6,-1.5)(0.4,0.2in)
\psbarcode[rotate=180,linecolor=red]{01335583}{includetext guardwhitespace height=0.6}{ean8}
\end{pspicture}}\quad
\psframebox{\begin{pspicture}(3.8,1in)
\psbarcode[scalex=1.5,scaley=0.5,transy=1]{01335583}{includetext inkspread=0.5}{ean8}
\end{pspicture}}
\end{LTXexample}
\begin{LTXexample}[pos=t,preset=\centering,wide]
\begin{pspicture}(2in,2in)
\psbarcode[file]{demo.tex}{}{qrcode}
\end{pspicture}
\end{LTXexample}
The contents of the external file \texttt{demo.tex}:
\VerbatimInput{demo.tex}
\newpage
\subsection{Examples for the PostScript options}
\begin{LTXexample}[pos=t,preset=\centering]
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{includetext guardwhitespace height=0.6}{ean8}
\end{pspicture}
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{textsize=15 includetext guardwhitespace height=0.6}{ean8}
\end{pspicture}
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{includetext inkspread=0.5}{ean8}
\end{pspicture}
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{includetext textpos=0}{ean8}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[pos=t,preset=\centering]
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{includetext guardwhitespace}{ean8}
\end{pspicture}
\begin{pspicture}(3.5,1.2in)
\psbarcode{01335583}{textsize=15 includetext guardwhitespace width=2}{ean8}
\end{pspicture}
\end{LTXexample}
\section{Usage}
By default the barcode has a width and a height of zero. Using the \Lcs{parbox}
macro or the \Lenv{pspicture} environment can reserve the needed space for
the barcode. The \Lcs{fbox} in the following examples is used
only for demonstration.
\xLps{code39}
\begin{LTXexample}[width=.5\linewidth]
foo
\fbox{%
\parbox[b][1in]{1.5in}{\psbarcode{241078}{includetext width=1.5 height=1}{code39}}}
bar
\end{LTXexample}
\xLps{code39}
\bigskip
\begin{LTXexample}[pos=l,width=.5\linewidth]
foo
\fbox{%
\begin{pspicture}(0,-8pt)(1.5in,1in)
\psbarcode{241078}{includetext width=1.5 height=1}{code39}
\end{pspicture}}
bar
\end{LTXexample}
\section{Possible barcodes}
The following section shows the symbologies that are supported by
the encoders, including the available features for each. This list
may not be up-to-date. If it does not contain any of the formats or
features that you require then check the project source code or
try the support mailing list.
\subsection{EAN-13}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 12 or 13 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\\hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\item[Notes] If just 12 digits are entered then the check digit is calculated automatically
\end{description}
\xLps{ean13}
\begin{LTXexample}[width=.3\linewidth]
\begin{pspicture}(3,1.2in)
\psbarcode[scalex=0.8,scaley=0.8]{9783865415561}{includetext guardwhitespace}{ean13}
\end{pspicture}
\end{LTXexample}
\subsection{EAN-8}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 8 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\
\hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\end{description}
\xLps{ean8}
\begin{LTXexample}[width=.3\linewidth]
\begin{pspicture}(-2,-1.2)(0,0.2in)
\psbarcode[rotate=180,linecolor=red]{01335583}{includetext guardwhitespace height=0.6}{ean8}
\end{pspicture}
\end{LTXexample}
\subsection{UPC-A}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 11 or 12 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\
\hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\item[Notes] If just 11 digits are entered then the check digit is
calculated automatically
\end{description}
\xLps{upca}
\begin{LTXexample}[pos=l,width=.3\linewidth,wide]
\begin{pspicture}(3,1.2in)
\psbarcode[transx=15pt,transy=10pt]{78858101497}{includetext}{upca}
\qdisk(0,0){3pt}\rput[lb](5pt,-10pt){Origin}
\end{pspicture}
\end{LTXexample}
\subsection{UPC-E}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 7 or 8 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\
\hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\item[Notes] If just 7 digits are entered then the check digit is calculated automatically
\end{description}
\xLps{upce}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(1.5,1.2in)
\psbarcode{0123456}{includetext}{upce}
\end{pspicture}
\end{LTXexample}
\subsection{EAN-5}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 5 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\end{description}
\xLps{ean5}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(2,1in)
\psbarcode{90200}{includetext guardwhitespace}{ean5}
\end{pspicture}
\end{LTXexample}
\subsection{EAN-2}
\begin{description}
\item[Characters] \verb+0123456789+
\item[Data] 2 digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\\hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\end{description}
\xLps{ean2}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(1,1in)
\psbarcode{38}{includetext guardwhitespace}{ean2}
\end{pspicture}
\end{LTXexample}
\subsection{ISBN}
An ISBN symbol is really an EAN-13 with a particular prefix, 978 for the older ISBN-10 format, and others for the new ISBN-13 format.
\begin{description}
\item[Characters] \verb+-0123456789+
\item[Data] 9 or 10 digits for ISBN-10 seperated appropriately with dashes
\item[Data] 12 or 13 digits for ISBN-13 seperated appropriately with dashes
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\item[Notes] If just 9 (ISBN-10) or 12 (ISBN-13) digits are entered then the human readable,
ISBN check digit is calculated automatically
\end{description}
\xLps{isbn}
\smallskip
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(3,1in)
\psbarcode{3-86541-114}{includetext guardwhitespace}{isbn}
\end{pspicture}
\end{LTXexample}
\bigskip\enlargethispage{2ex}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(3,1in)
\psbarcode{978-3-86541-114}{includetext guardwhitespace}{isbn}
\end{pspicture}
\end{LTXexample}
\subsection{Code-39}
\begin{description}
\item[Characters] \verb+0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*+ %$
\item[Data] Variable number of characters, digits and any of the symbols \texttt{-.\@ *\$/+\%}.
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includecheck} & Enable check digit\\
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make check digit visible in text\\
\end{tabular}
\end{description}
\begin{LTXexample}[pos=l,width=.4\linewidth,wide]
\begin{pspicture}(5,1in)
\psbarcode{CODE-39}{includecheck includetext}{code39}
\end{pspicture}
\end{LTXexample}
\subsection{Code-128 and UCC/EAN-128}
\begin{description}
\item[Characters] \verb|!"#$%&'\(\)*+,-./0...9:;<=>?@A...Z[\\]^_`a...z|\verb+{|}~+ %$
\item[Data] Variable number of ASCII characters and special
funtion symbols, starting with the approriate start character
for the initial character set. UCC/EAN-128s must have a manditory
\texttt{FNC 1} symbol immediately following the start character.
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make check digit visible in text\\
\end{tabular}
\item[Notes] Any non-printable character can be entered via its escaped
ordinal value, for example \texttt{\^{}070} for \texttt{ACK}
and \texttt{\^{}102} for \texttt{FNC 1}. Since a caret symbol
serves as an escape character it must be escaped as \texttt{\^{}062}
if used in the data. The check character is always added automatically.
\end{description}
\begin{LTXexample}[width=.5\linewidth]
\begin{pspicture}(5,1in)
\psbarcode{^104^102Count^0991234^101!}{includetext}{code128}
\end{pspicture}
\end{LTXexample}
\subsection{Rationalized Codabar}
\begin{description}
\item[Characters] \verb!0123456789-$:/.+ABCD! %$
\item[Data] Variable number of digits and any of the symbols \texttt{-\$:/.+ABCD}.
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includecheck} & Enable check digit\\
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make check digit visible in text\\
\end{tabular}
\end{description}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(4,1in)
\psbarcode{A0123456789B}{includetext}{rationalizedCodabar}
\end{pspicture}
\end{LTXexample}
\newpage
\subsection{Interleaved 2 of 5 and ITF-14}
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number of digits. An ITF-14 is 14 characters and
does not have a check digit.
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includecheck} & Enable check digit\\
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make check digit visible in text\\
\end{tabular}
\item[Notes] The data may be automatically prefixed with 0 to make the
data, including optional check digit, of even length.
\end{description}
\begin{LTXexample}[width=.5\linewidth]
\begin{pspicture}(5,0.7in)
\psbarcode{05012345678900}{includecheck height=0.7}{interleaved2of5}
\end{pspicture}
\end{LTXexample}
\subsection{Code 2 of 5}
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number of digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\end{description}
\begin{LTXexample}[width=.5\linewidth]
\begin{pspicture}(5,1.2in)
\psbarcode{0123456789}{includetext textpos=75 textfont=Helvetica textsize=16}{code2of5}
\end{pspicture}
\end{LTXexample}
\clearpage
\subsection{Postnet}
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make the check digit visible in the text
\end{tabular}
\item[Notes] Check digit is always added automatically
\end{description}
\begin{LTXexample}[width=.6\linewidth]
\begin{pspicture}(7,0.3in)
\psbarcode{01234}{includetext textpos=-10 textfont=Arial textsize=10}{postnet}
\end{pspicture}
\end{LTXexample}
\subsection{Royal Mail}
\begin{description}
\item[Characters] \verb!ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS!
\item[Data] Variable number digits and capital letters
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make the check digit visible in the text
\end{tabular}
\item[Notes] Check digit is always added automatically
\end{description}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(5,0.5in)
\psbarcode{LE28HS9Z}{includetext}{royalmail}
\end{pspicture}
\end{LTXexample}
\subsection{Kix (Customer index) -- Dutch Mail}
\begin{description}
\item[Characters] \verb!ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS!
\item[Data] Variable number digits and capital letters
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
% \texttt{includecheckintext} & Make the check digit visible in the text
\end{tabular}
\item[Notes] Check digit is always added automatically
\end{description}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(5,0.3in)
\psbarcode{1203AA12}{includetext}{kix}
\end{pspicture}
\end{LTXexample}
\subsection{Australian postal service}
\begin{description}
\item[Characters] \verb!ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRSabc...xyz!
\item[Data] Variable number digits and letters
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make the check digit visible in the text
\end{tabular}
%\item[Notes] Check digit is always added automatically
\end{description}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(5,0.3in)
\psbarcode{1139549554}{includetext}{auspost}
\end{pspicture}
\end{LTXexample}
\subsection{Japan post service}
\begin{description}
\item[Characters] \verb!ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRSabc...xyz!
\item[Data] Variable number digits and letters
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make the check digit visible in the text
\end{tabular}
%\item[Notes] Check digit is always added automatically
\end{description}
\begin{LTXexample}[pos=t]
\begin{pspicture}(0,-5mm)(7,0.5in)
\psbarcode{6540123789-A-K-Z}{includetext textxalign=center}{japanpost}
\end{pspicture}
\end{LTXexample}
\subsection{onecode}
%United States Postal Service, replaces POSTNET and PLANET symbols.
%Each barcode can be 20, 25, 29, or 31 digits long, depending on the type of ZIP code present. Each digit has four possible states, so one digit represents numbers 0-3.
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number digits
\iffalse
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\ \hline
\texttt{includetext} & Enable human readable text\\
\end{tabular}
\fi
\end{description}
\begin{LTXexample}[pos=t,preset=\centering]
\begin{pspicture}(0,-5mm)(5,0.3in)
\psbarcode{0123456709498765432101234567891}{includetext}{onecode}
\end{pspicture}
\end{LTXexample}
\subsection{Symbol}
The purpose of the symbol encoder is to store the definitions of miscellaneous barcode
symbols such as the FIM symbols used by the US Postal Service on their reply mail.
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(1cm,1.5cm)
\psbarcode{fima}{}{symbol}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(1cm,1.5cm)
\psbarcode{fimb}{}{symbol}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(1cm,1.5cm)
\psbarcode{fimc}{}{symbol}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=.4\linewidth]
\begin{pspicture}(1cm,1.5cm)
\psbarcode{fimd}{}{symbol}
\end{pspicture}
\end{LTXexample}
\subsection{MSI}
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number digits
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\\hline
\texttt{includecheck} & Enable check digit\\
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make check digit visible in the text
\end{tabular}
\end{description}
\begin{LTXexample}[pos=l,width=.5\linewidth,wide]
\begin{pspicture}(6,1in)
\psbarcode{0123456789}{includecheck includetext}{msi}
\end{pspicture}
\end{LTXexample}
\subsection{Plessey}
\begin{description}
\item[Characters] \verb!01234B6789ABCDEF!
\item[Data] Variable number of hexadecimal characters
\item[Options]~\\
\begin{tabular}{l|l}
Option & Feature\\\hline
\texttt{includetext} & Enable human readable text\\
\texttt{includecheckintext} & Make the check digits visible in the text
\end{tabular}
\item[Notes] Check digits are always added automatically.
\end{description}
\begin{LTXexample}[pos=t,preset=\centering]
\begin{pspicture}(0,-2mm)(12,1in)
\psbarcode{0123456789ABCDEF}{includetext}{plessey}
\end{pspicture}
\end{LTXexample}
\subsection{Reduced Space Symbology (RSS)}
This is a family that includes RSS-14\textregistered, RSS Limited\textregistered,
and RSS Expanded\textregistered{} (\url{http://www.gs1.org/productssolutions/barcodes/technical/rss.html}).
RSS-14 and RSS Limited encode Global Trade Item
Numbers (GTINs). RSS Expanded will encode any of the GS1 System identification
numbers as well as all other Application Identifiers.
RSS is used in the healthcare industry.
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number digits
\end{description}
\subsubsection{rss14 (databaromni)}
\begin{LTXexample}[width=.3\linewidth]
\begin{pspicture}(12,.3in)
\psbarcode{(01)24012345678905}{format=truncated includetext height=0.3}{databaromni}
\end{pspicture}
\end{LTXexample}
\subsubsection{rsslimited (databarlimited)}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(12,.3in)
\psbarcode{(01)15012345678907}{height=0.3}{databarlimited}
\end{pspicture}
\end{LTXexample}
\subsubsection{rssexpanded (databarexpanded)}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(12,.3in)
\psbarcode{(10)12A}{height=0.3}{databarexpanded}
\end{pspicture}
\end{LTXexample}
\subsection{Pharmacode}
For a documentation see \url{http://www.laetus.com/laetus.php?request=file&id=69}.
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number digits
\end{description}
\begin{LTXexample}[pos=l,width=.3\linewidth]
\begin{pspicture}(12,.3in)
\psbarcode{117480}{}{pharmacode}
\end{pspicture}
\end{LTXexample}
\subsection{PDF417}
For a documentation see \url{http://de.wikipedia.org/wiki/Strichcode#PDF417}.
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number characters
\end{description}
\begin{LTXexample}[pos=l,width=2in,wide]
\begin{pspicture}(2in,0.3in)
\psbarcode{^453^178^121^239}{columns=2 rows=10}{pdf417}
\end{pspicture}
\end{LTXexample}
\subsection{Data matrix}
For a documentation see \url{http://de.wikipedia.org/wiki/Strichcode#DataMatrix}.
It is a 2D matrix-style barcode that can encode full 256 character extended-ASCII.
Also known as: Data Matrix ECC 200.
Variants:
\begin{description}
\item[GS1] DataMatrix is a variant of Data Matrix that should be used when encoding data that is in
GS1 Application Identifier standard format.
\item[HIBC] Data Matrix is a variant of Data Matrix that should be used when encoding
HIBC formatted data.
\end{description}
Standards: ISO/IEC 16022, ANSI/AIM BC11 ISS.
Data and Options
\begin{itemize}
\item The data field can contain any extended ASCII data.
\item When the parse option is specified, any instances of \verb|^NNN| in the data field
are replaced with their equivalent ASCII value, useful for specifying unprintable characters.
\item When the parsefnc option is specified, non-data function characters can be specified by \verb|^FNC1|.
\item The columns and rows options are used to specify the size of the symbol, either square or rectangular, one of:
Square: 10x10, 12x12, 14x14, 16x16, 18x18, 20x20, 22x22, 24x24, 26x26, 32x32, 36x36, 40x40,
44x44, 48x48, 52x52, 64x64, 72x72, 80x80, 88x88, 96x96, 104x104, 120x120, 132x132, 144x144
Rectangular: 8x18, 8x32, 12x26, 12x36, 16x36, 16x48
\item If the columns and rows are unspecified, the encoder will default to creating a (non-rectangular)
symbol that is the minimum size to represent the given data.
\item The raw option denotes that the data field is providing the input as a pre-encoded codewords in \verb|^NNN|
format, suitable for direct low-level encoding.
\item The encoding option specifies how the data is to be encoded. Possible values are:
\begin{itemize}
\item encoding=ascii - Extended ASCII data (default).
\item encoding=c40 - Optimized encoding for upper-case alphanumeric data. Can also encode extended ASCII
data but incurs extra codeword overhead.
\item encoding=text - Optimized encoding for lower-case alphanumeric data. Can also encode
extended ASCII data but incurs extra codeword overhead.
\item encoding=x12 - Optimized encoding restricted to upper-case alphanumeric data plus the characters \verb|\r * >| and space.
\item encoding=raw - Same as the raw option.
\end{itemize}
\item The prefix option allows adding a special codeword to the symbol prior to the data. Possible values are:
\begin{itemize}
\item prefix=MAC5 - Prefixes the data with the 05 Macro codeword.
\item prefix=MAC6 - Prefixes the data with the 06 Macro codeword.
\item prefix=PROG - Prefixes the data with the reader programming codeword. May require encoding=c40, depending on the reader.
\item prefix=FNC1 - Prefixes the data with the FNC1 codeword.
\end{itemize}
\end{itemize}
\begin{description}
\item[Characters] extended ASCII
\item[Data] Variable number characters
\end{description}
\begin{LTXexample}[pos=l,width=1.6in,wide]
\begin{pspicture}(1.5in,1.5in)
\psbarcode{Herbert Voss ^142^164^186}{rows=48 columns=48 parse}{datamatrix}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=1.6in,wide]
\begin{pspicture}(1in,1in)
\psbarcode{^098^099^100^142^164^186^101^102^103^104^105}{raw}{datamatrix}
\end{pspicture}
\end{LTXexample}
\subsection{2D Maxi code}
For a documentation see \url{http://www.logicalconcepts.eu/wDeutsch/autoid/barcodetypen/index.html?navid=21}.
MaxiCode is a fixed-sized two-dimensional symbology created by the
United Parcel Service that is primarily used for freight sortation
and tracking. It's symbols have modules arranged in a hexagonal
grid around a circular finder pattern which can be read omnidirectionally.
\begin{itemize}
\item MaxiCode has five alphabets A, B, C, D and E, each containing 64 characters.
\begin{itemize}
\item Alphabet A contains mostly upper case letters, numbers and some common ASCII symbols.
\item Alphabet B contains mostly lower case letters and common ASCII symbols.
\item Alphabet C contains mostly upper case letters from the extended ASCII character set and less common ASCII symbols.
\item Alphabet D contains mostly lower case letters from the extended ASCII character set and less common ASCII symbols.
\item Alphabet E contains mostly the special ASCII characters and unprintable symbols.
\end{itemize}
\item Non-printable/typable characters can be entered as their escaped ordinal values, e.g. \textasciicircum 028 for FS and \textasciicircum 059 for [shift B], etc.
\item The symbol always starts in alphabet A which is suitable for the most basic contents.
\item You can switch the working alphabet within the data using the [latch B], [latch A], ... characters.
\item You can temporarily shift to another alphabet for a varying number of characters using the [shift A], [2 shift A], [3 shift A], ... characters.
\item You can remain in an alphabet to which you have shifted using the [lock in C], [lock in D], ... characters.
\item There are also more advanced features for encoding for which a thorough reading of the specification is required as these cannot be described succinctly here.
\end{itemize}
The modes:
\begin{itemize}
\item Mode 0 - Obsolete. (Older printers will produce Mode 0 if the firmware is outdated. Mode 0 MaxiCodes can be visually determined by examining the two horizontal hexagons in the upper right-hand corner. They will be white if the Mode is 0. For all other modes, they are black.)
\item Mode 2 - Used for Numeric postal codes. (Primary use is US domestic destinations.)
\item Mode 3 - Used for Alphanumeric postal codes. (Primary use is Int'l destinations.)
\item Mode 4 - Standard Error Correction.
\item Mode 5 - Enhanced Error Correction.
\item Mode 6 - Used for programming hardware devices.
\end{itemize}
%(^059^042^041^059^040^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291^0471^029^029Y^029634
%ALPHA DR^029PITTSBURGH^029PA^030^062^004^063) (mode 2 parse) maxicode barcode
\begin{description}
\item[Characters] \verb!@ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!
\item[Data] Variable number characters
\end{description}
\begin{LTXexample}[width=1in,wide]
\begin{pspicture}(1in,1in)
\expandafter\psbarcode{[\string\)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004}{mode=2 parse}{maxicode}
\end{pspicture}
\end{LTXexample}
\subsection{Aztec Code}
Aztec Code is a 2 dimensional matrix style bar code symbology.
Aztec Code was invented by Andrew Longacre (USA) in 1995
(\url{http://de.wikipedia.org/wiki/Aztec_Code}).
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number characters
\end{description}
\begin{LTXexample}[pos=l,width=1in,wide]
\begin{pspicture}(1in,1in)
\psbarcode{0123456789}%
{format=compact layers=3}{azteccode}
\end{pspicture}
\end{LTXexample}
%315 140 moveto (00100111001000000101001101111000010100111100101000000110) (format=compact layers=3) azteccode barcode
%0 -10 rmoveto (Aztec Code) show
\subsection{itf14}
%Aztec Code is a 2 dimensional matrix style bar code symbology.
%Aztec Code was invented by Andrew Longacre (USA) in 1995
%(\url{http://de.wikipedia.org/wiki/Aztec_Code}).
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number characters
\end{description}
\begin{LTXexample}[width=1.5in,wide]
\begin{pspicture}(1in,1in)
\psbarcode{1001234567890}{showborder borderwidth=4 borderleft=15 borderright=15 height=0.5 includecheck includetext includecheckintext textyoffset=-10}{interleaved2of5}
\end{pspicture}
\end{LTXexample}
\subsection{QR Code}
A QR Code (Quick Response) is a 2 dimensional matrix code created by Japanese
corporation Denso-Wave in 1994 (\url{http://de.wikipedia.org/wiki/QR_Code}).
\begin{description}
\item[Characters] \verb!0123456789!
\item[Data] Variable number characters
\end{description}
The data field can contain any extended ASCII data.
When the parse option is specified, any instances of \verb|^NNN| in the data field are
replaced with their equivalent ASCII value, useful for specifying unprintable characters.
The eclevel option is used to specify the error correction level:
\begin{description}
\item[eclevel=L] - Low (default for micro format symbols)
\item[eclevel=M] - Medium (default for full format symbols)
\item[eclevel=Q] - Quality
\item[eclevel=H] - High
\end{description}
The eclevel will be opportunistically raised when this does not result in an increased symbol size.
The encoding option is used to specify a desired encoding for the input data which can sometimes result in a more optimal symbol size:
\begin{description}
\item[encoding=alphanumeric] - Alphanumeric data
\item[encoding=numeric] - Numeric data
\item[encoding=byte] - Byte based encoding
\item[encoding=kanji] - Kanji characters based on Shift JIS
\item[encoding=raw] - Equivalent to the raw option
If left unspecified the optimal available encoding will be chosen for the given data in
the following order of preference: numeric, alphanumeric, kanji, byte.
The version option is used to specify the size of the symbol, 1 to 40 for full
format symbols or \verb|version=M1|, \verb|version=M2|, \verb|version=M3| or \verb|version=M4|
for micro format symbols.
If unspecified, the encoder will select the version of the symbol that is the minimum
size to represent the given data at the selected error correction level.
The format option is used to select between format=full and format=micro symbol
types. By default, full format symbols will be generated.
The raw option denotes that the data field is providing the input as a pre-encoded
bitstream (excluding the terminator bits) suitable for direct low-level encoding.
\end{description}
\begin{LTXexample}[pos=l,width=1in]
\begin{pspicture}(1in,1in)
\psbarcode{http://www.dante.de}{}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1.5in]
\begin{pspicture}(1in,1in)
\psbarcode{http://www.dante.de}{eclevel=M}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1.5in]
\begin{pspicture}(1in,1in)
\psbarcode{QR ^067ode}{parse}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1.5in]
\begin{pspicture}(2in,2in)
\psbarcode{QR CODE 1234}{version=10 eclevel=Q}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1.5in]
\begin{pspicture}(0.5in,0.5in)
\psbarcode{01234567}{format=micro}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1.5in]
\begin{pspicture}(1in,1in)
\psbarcode{000100000010000000001100010101100110000110000}{raw}{qrcode}
\end{pspicture}
\end{LTXexample}
\begin{LTXexample}[width=1in,wide]
\begin{pspicture}(0.5in,0.5in)
\psbarcode{0010000000000110001010110011010100110111000010100111010100101}{format=micro raw}{qrcode}
\end{pspicture}
\end{LTXexample}
\section{Code Commentary}
This commentary assumes familiarity with the PostScript
language\footnote{The PostScript Language Tutorial and Cookbook
(a.k.a. the Blue Book), which is freely available online, serves
as both a useful tutorial and reference manual to the language.}.
The code is split cleanly into two types of procedure:
\begin{description}
\item[The encoders]{Each of these represents a barcode
symbology\footnote{By symbology we mean an accepted standard for
representation of data as a barcode},
e.g. EAN-13 or Code-128. It takes a string containing the barcode
data and a string containing a list of options that modify the
output of the encoder. It generates
a structured representation of the barcode and its text for the
symbology, including the calculation of check digits where necessary.}
\item[The renderer]{This takes the output of an encoder and
generates a visual representation of the barcode.}
\end{description}
This means that all barcodes can be generated simply in a similar
manner:
\begin{lstlisting}
(78858101497) (includetext height=0.6) upca barcode
(0123456789) (includecheck) interleaved2of5 barcode
\end{lstlisting}
\subsection{The Barcode Data Structure}
\label{datastructure}
The following table describes the structured representation of a
barcode that is passed by an encoder to the renderer as a
dictionary when the PostScript is executed.
\begin{center}
\begin{tabular}{l|c|p{6.5cm}}\hline
\emph{Element} & \emph{Key} & \emph{Value} \\\hline
Space bar succession & \texttt{sbs} &
String containing the integer widths, in points, of each bar and
space, starting with the leftmost bar.\\
Bar height succession & \texttt{bhs} &
Array containing the height of each bar in inches, starting with
the leftmost bar.\\
Bar base succession & \texttt{bbs} &
Array containing the offset of the base of each bar in inches,
starting with the leftmost bar.\\
Human readable text & \texttt{txt} &
Array of arrays that contain the character, position, height,
font and scale factor (font size), in points, for each of the visible
text characters.\\\hline
\end{tabular}
\end{center}
\subsection{An Encoder}
The procedure labelled code2of5 is a simple example of an encoder,
which we will now consider. Its purpose is to accept as input a string
containing the barcode contents and a string containing a list of options,
and to process these in a way
that is specific to this encoder, and finally to output an
instance of the dictionary-based data structure described in section
\ref{datastructure} that represents the barcode contents in the
Code 2 of 5 symbology.
As with all of the encoders, the input string is assumed to be valid for
the corresponding symbology, otherwise the behaviour is undefined.
The variables that we use in this procedure are confined to local
scope by declaring the procedure as follows:
\begin{lstlisting}
/code2of5 {
0 begin
...
end
} bind def
/code2of5 load 0 1 dict put
\end{lstlisting}
We start by immediately reading the contents strings that are passed as
arguments to this procedure by the user.
\begin{lstlisting}
/options exch def
/barcode exch def
\end{lstlisting}
We initialise a few default variables. Those variables corresponding to
options that can be enabled with the options argument are initially
set to false.
\begin{lstlisting}
/includetext false def
/textfont /Courier def
/textsize 10 def
/textpos -7 def
/height 1 def
\end{lstlisting}
The options string is tokenised with each successive token defining either a
name value pair which we instantiate or a lone variable that we define as true,
allowing us to override the given default variables given above.
\begin{lstlisting}
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
\end{lstlisting}
Since any user given options create variables that are strings we need to convert
them back to their intended types.
\begin{lstlisting}
/textfont textfont cvlit def
/textsize textsize cvr def
/textpos textpos cvr def
/height height cvr def
\end{lstlisting}
We then create an array of string encodings for each of the available
characters which we then declare in another string. This information
can be derived from careful reading of the relevant specification,
although this is often surprisingly difficult to obtain.
\begin{lstlisting}
/encs
[ (1111313111) (3111111131) (1131111131) (3131111111)
(1111311131) (3111311111) (1131311111) (1111113131)
(3111113111) (1131113111) (313111) (311131)
] def
/barchars (0123456789) def
\end{lstlisting}
We now store the length of the content string and calculate the
total number of bars and spaces in the resulting barcode.
We initialise a string of size dependant on this length into
which we will build the space bar succession. Similarly, we create
an array into which we will add the human readable text information.
\begin{lstlisting}
/barlen barcode length def
/sbs barlen 10 mul 12 add string def
/txt barlen array def
\end{lstlisting}
We now begin to populate the space bar succession by adding the
encoding of the start character to the beginning.
\begin{lstlisting}
sbs 0 encs 10 get putinterval
\end{lstlisting}
We now enter the main loop which iterates over the content string
from start to finish, looking up the encoding for each character,
adding this to the space bar succession.
It is important to understand how the encoding for a given character
is derived. Firstly, given a character, we find its position in the
string of all available characters. We then use
this position to index the array of character encodings to obtain
the encoding for the given character, which is added to the space/bar
succession. Likewise, the character is added to the array of human
readable text along with positioning and font information.
\begin{lstlisting}
0 1 barlen 1 sub {
/i exch def
barcode i 1 getinterval barchars exch search
pop
length /indx exch def
pop pop
/enc encs indx get def
sbs i 10 mul 6 add enc putinterval
txt i [barcode i 1 getinterval i 14 mul 10 add -7
textfont textsize] put
} for
\end{lstlisting}
The encoding for the end character is obtained and added to
the end of the space bar succession.
\begin{lstlisting}
sbs barlen 10 mul 6 add encs 11 get putinterval
\end{lstlisting}
Finally we prepare to push a dictionary containing the space bar
succession (and any additional information defined in section
\ref{datastructure}) that will be passed to the renderer.
\begin{lstlisting}
/retval 1 dict def
retval (sbs) sbs put
retval (bhs) [sbs length 1 add 2 idiv {height} repeat] put
retval (bbs) [sbs length 1 add 2 idiv {0} repeat] put
includetext {
retval (txt) txt put
} if
retval
\end{lstlisting}
\subsection{The Renderer}
The procedure labelled barcode is known as the renderer, which we now
consider. Its purpose is to accept as input an instance of the
dictionary-based data structure described in section
\ref{datastructure} that represents a barcode in some arbitrary
symbology and produce a visual rendering of this at the current
point.
The variables that we use in this procedure are confined to local
scope by declaring the procedure as follows:
\begin{lstlisting}
/barcode {
0 begin
...
end
} bind def
/barcode load 0 1 dict put
\end{lstlisting}
We then immediately read the dictionary-based data structure which
is passed as a single argument to this procedure by an encoder, from
which we extract the space bar succession, bar height succession and bar
base succession.
\begin{lstlisting}
/args exch def
/sbs args (sbs) get def
/bhs args (bhs) get def
/bbs args (bbs) get def
\end{lstlisting}
We attempt to extract from the dictionary the array containing the
information about human readable text. However, this may not exist
in the dictionary in which case we create a default empty array.
\begin{lstlisting}
args (txt) known
{
/txt args (txt) get def
}
{
/txt [] def
} ifelse
\end{lstlisting}
We have extracted or derived all of the necessary information
from the input, and now use the space bar succession, bar height
succession and bar base succession in calculations that create a
single array containing elements that give coordinates for each of
the bars in the barcode.
We start by creating a bars array that is half the length of the
space bar succession. We build this by repeatedly adding array elements
that contain the height, x-coordinate, y-coordinate and width of
single bars. The height and y-coordinates are read from the bar
height succession and the bar base succession, respectively, whilst
the x-coordinate and the width are made from a calculation of the
total indent, based on the space bar succession and a compensating
factor that accounts for ink spread.
\begin{lstlisting}
/bars sbs length 1 add 2 idiv array def
/x 0.00 def
0 1 sbs length 1 sub {
/i exch def
/d sbs i get 48 sub def
i 2 mod 0 eq
{
/h bhs i 2 idiv get 72 mul def
/c d 2 div x add def
/y bbs i 2 idiv get 72 mul def
/w d 0.15 sub def
bars i 2 idiv [h c y w] put
} if
/x x d add def
} for
\end{lstlisting}
Finally, we perform the actual rendering in two phases. Firstly we
use the contents of the bars array that we just built to render each
of the bars, and secondly we use the contents of the text array
extracted from the input argument to render the
text. We make an efficiency saving here by not performing loading and
rescaling of a font if the scale factor for the font size is 0. The graphics
state is preserved across calls to this procedure to prevent
unexpected interference with the users environment.
\begin{lstlisting}
gsave
bars {
{} forall
setlinewidth moveto 0 exch rlineto stroke
} forall
txt {
{} forall
dup 0 ne {exch findfont exch scalefont setfont}
{pop pop}
ifelse
moveto show
} forall
grestore
\end{lstlisting}
\subsection{Notes Regarding Coding Style}
PostScript programming veterans are encouraged to remember that the
majority of people who read the code are likely to have little,
if any, prior knowledge of the language.
To encourage development, the code has been written with these
goals in mind:
\begin{itemize}
\item[-]{That it be easy to use and to comprehend}
\item[-]{That it be easy to modify and enhance}
\end{itemize}
To this end the following points should be observed for all new
code submissions:
\begin{itemize}
\item[-]{New encoders should be based on the code of a similar
existing encoder}
\item[-]{Include comments where these clarify the operations
involved, particular where something unexpected happens}
\item[-]{Prefer simplicity to efficency and clarity to
obfuscation, except where this will be a problem}
\end{itemize}
\subsection{Installing the Barcode Generation Capability into a Printer's Virtual Machine}
Most genuine PostScript printers allow procedures to be defined such
that they persist across different jobs through the use of the \texttt{exitserver}
command. If your printer supports this then you will be able to print
the main code containing the definitons of all the encoders and the
renderer once, e.g. soon after the device is turned on, and later omit
these definitons from each of the barcode documents that you print.
To install the barcode generation capabilities into the
virtual machine of a PostScript printer you need to uncomment a line near the
top of the code so that it reads:
\begin{lstlisting}
serverdict begin 0 exitserver
\end{lstlisting}
Once this code is printed the procedural definitions for the encoders and
the renderer will remain defined across all jobs until the device is reset
either by power-cycling or with the following code:
\begin{lstlisting}
serverdict begin 0 exitserver systemdict /quit get exec
\end{lstlisting}
\section{List of all optional arguments for \texttt{pst-barcode}}
\xkvview{family=pst-barcode,columns={key,type,default}}
\bgroup
\raggedright
\nocite{*}
\bibliographystyle{plain}
\bibliography{\jobname}
\egroup
\printindex
\end{document}
\clearpage
\section{Package code}
\subsection{\texttt{pst-barcode.sty}}
\lstinputlisting[xleftmargin=-1cm,xrightmargin=-1cm]{pst-barcode.sty}
\subsection{\texttt{pst-barcode.tex}}
\lstinputlisting[xleftmargin=-1cm,xrightmargin=-1cm]{pst-barcode.tex}
%\subsection{\texttt{pst-barcode.pro}}
%\lstinputlisting[language={},xleftmargin=-1.5cm,xrightmargin=-1.5cm]{pst-barcode.pro}
\iffalse
30 500 moveto (CODE 39) (includecheck includetext) /code39 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Code 39) show
385 200 moveto (THIS IS CODE 93) (includecheck includetext) /code93 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Code 93) show
375 400 moveto (\(00\)030123456789012340|\(02\)13012345678909\(37\)24\(10\)1234567ABCDEFG) (ccversion=c includetext) /gs1-128composite /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (GS1-128 Composite) show
150 700 moveto (0123456789) (includecheck includetext) /interleaved2of5 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Interleaved 2 of 5) show
215 300 moveto ((01)24012345678905) (includetext) /databartruncated /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (DataBar Truncated) show
250 250 moveto ((01)24012345678905) () /databarstacked /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (DataBar Stacked) show
220 560 moveto ((01)15012345678907) () /databarlimited /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (DataBar Limited) show
220 500 moveto ((10)12A) () /databarexpanded /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (DataBar Expanded) show
215 348 moveto (117480) (includetext) /pharmacode /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Pharmacode) show
30 300 moveto (01234567) (includetext includecheck) /code2of5 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Code 2 of 5) show
165 600 moveto (0124589) <<
/includetext true
/includecheck true
/barcolor (AA0000)
/textyoffset -8
/textcolor (008888)
/backgroundcolor (2020FF0F)
/showborder true
/bordercolor (0000FF)
>> /code11 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Code 11) show
30 400 moveto (A0123456789B) (includecheck includetext) /rationalizedCodabar /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Rationalized Codabar) show
420 700 moveto (977147396801 05) (includetext guardwhitespace) /ean13 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (EAN-13) show
41 700 moveto (01335583) (includetext guardwhitespace) /ean8 /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (EAN-8) show
37 600 moveto (78858101497) (includetext) /upca /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (UPC-A) show
315 700 moveto (0425261) (includetext) /upce /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (UPC-E) show
405 600 moveto (978-1-86074-271 54495) (includetext) /isbn /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (ISBN) show
345 515 moveto (0123456709498765432101234567891) (includetext) /onecode /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (OneCode) show
215 455 moveto (01234) (includetext) /postnet /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Postnet) show
215 410 moveto (LE28HS9Z) (includetext) /royalmail /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Royal Mail) show
400 165 moveto (1231FZ13XHS) (includetext) /kix /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (KIX) show
335 555 moveto (6540123789-A-K-Z) (includetext textxalign=center) /japanpost /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (JapanPost) show
385 132 moveto (5956439111ABA 9) (includetext) /auspost /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (AusPost) show
348 300 moveto (123456) (includecheck includetext) /msi /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (MSI) show
30 200 moveto (123AB) (includetext) /plessey /uk.co.terryburton.bwipp findresource exec
0 -17 rmoveto (Plessey) show
47 135 moveto (10012345678902) (includetext) /itf14 /uk.co.terryburton.bwipp findresource exec
-15 -20 rmoveto (ITF-14) show
245 125 moveto (http://lwn.net) () /qrcode /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (QR Code) show
245 190 moveto (This is PDF417) (columns=2 color=442222 backgroundcolor=AABBCC) /pdf417 /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (PDF417) show
300 600 moveto (http://www.terryburton.co.uk/barcodewriter/) (rows=48 columns=48) /datamatrix /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (Data Matrix) show
315 125 moveto (This is Aztec Code) (format=compact layers=3) /azteccode /uk.co.terryburton.bwipp findresource exec
0 -10 rmoveto (Aztec Code) show
\fi
|