French version

The PDF417 code.



This code is part of the family of 2-dimensional codes, it's in fact a code of several lines which can encode up to 2700 bytes what explain its name "Portable Document File". The encoding is done in two stages : first the datas are converted into "codeword" (High level encoding) then those are converted to bars and spaces patterns. (Low level encoding) In addition, a multi-level error correction system is included, it allows to reconstruct badly printed, erased, fuzzy or torn off datas. In the remainder of this presentation, the expression "codeword" will be shortened to CW and "Reed-Solomon code" to RS.

The general structure.
Beginning
G1 D15 D14 Dr1 G2 D13 D12 Dr2 G3 D11 D10 Dr3 G4 D9 D8 Dr4 G5 D7 D6 Dr5 G6 D5 D4 Dr6 G7 D3 D2 Dr7 G8 D1 D0 Dr8 G9 C3 C2 Dr9 G10 C1 C0 Dr10
End

Low level encoding.

High level encoding.

Errors detection and correction.
Find all the RS code calculations of the different 2D barcodes in Visual Basic 6.
It is a ZIP file without installation :

Those who have read and understood the codes of Reed Solomon will find themselves there ; for the few ignorant who have not understood everything (like me!) It will be enough to apply the "recipe" by using the codes obtained in the reverse order (last to first).

Bar code making.
Since we can create the bar code pattern it remains us to draw it on the screen and to print it on a paper sheet. Two approaches are possibles : It seems there is no free font for PDF417 on the net. I've decided consequently to draw this font and to propose it for download. Because there's 929 CWs with 3 alternatives for each one obligate us to divide the 17 bits of a CW in several parts. But divide by 17 ... hmmm ... a trick is necessary. If we considere that the first bit is always "1" and the last one "0", we can imagine a separator like "01" and the remain is only 15 bits in each CW; we can then divide these 15 bits into 3 parts. There will be then 25 = 32 possible groups affected to 32 characters of the font. The encoding software is in charge to transform the 3 groups of each CW into a 3 characters string.
The font will contain thus the following characters : The string to send to the printer will look something like this  : +*gfA*jhD*BAl*gCt*hjk*- and this for each row.

The "pdf417.ttf" font
This font contains the 35 patterns describe above. The start row and end row codes embed a 2 modules margin. The height is equal to 3 modules which is the most usual size.

Copy this file in the font directory, often named : \Windows\Fonts

Encoding a pdf417 bar code.

The software will evolve with 4 steps : Because of the interaction between the different compaction modes and the different sub-modes of the "text" mode it's difficult to make a 100% optimization. Thus the software will split the string into "parts" having the type "numeric", "text" or "byte" afterwards it will change some parts for an other mode if the overload due to switch CWs is greater than the compaction gain. We'll can't make allowance for all the parameters like paddings, gain due to perfect multiple of 6, uni-character switch or the switchs between the different sub-modes of the text mode : one would need for that several thousands of programming lines.
Another difficulty comes from the size of the wielded numbers, for example the "Modulo 900" operation applied on a 44 digits number generate an unavoidable overload error; the software will have to carry out this calculation step by step.

A small program to test all that.

Here is a small program written with Visual Basic 6.
The setup file copy the program, Visual Basic
dependencies, source files and the font.

Setup file :

ZIP file without setup :

The PDF417$ function have about 500 lines, I thus don't reproduce it here, you can retrieve it in the "form1.frm" file which is with the above program ; with setup program, the "form1.frm" file is in the program directory, "sources" sub-directory.
The function call is like this : resultat$ = pdf417$(Chaine$, Sécu%, NbCol%, CodeErr%)
with the string to encode in String$, correction level in Security% (-1 = auto.), ColNb% for the number of data columns in a row (<1 = auto.) and ErrCode% for retrieving an eventual error code. these 3 last parameters are not required and are passed by references ; after the function return they contains the really used values. Values of ErrCode% after the function return : It is enough now to display or to print the chains result$ with the pdf417 font for example in a text processing. The Office users will be able to even integrate the pdf417$ function in a macro to automate the treatment. To achieve all the treatments in a single function, I had to use "Gosub" instead of functions with parameters ; I can already hear the programming esthetes screaming sacrilegious !


Do you like this page ?

Is it useful for you ?
Click here !