Barcode fonts enable you to include printable barcodes on
documents, labels or reports. While font-based barcodes do not offer
the versatility of picture-based barcodes, there are situations in
which they are required (such as when using Word's Mailmerge
facility) or desirable (such as when storing large numbers of
barcodes in databases or spreadsheets without the storage overhead
of picture-based barcodes).
Font based barcodes are made of text strings which when displayed or printed in the appropriate font form the bars of the barcode. Only in a very limited number of cases is the text string easily related to the data required in the barcode. For example, if you take the characters (1234) and change the font to our Code 39 font, then you get a correct barcode as shown in the image below:
Code 39 barcode
The bracket characters in the above are used for the first few and last few bars - known as the Start and Stop characters - and there is a simple correspondence between the data characters and the bars in the barcode, ie a pattern for the character 1, and another for the character 2, etc.
For most other barcode types this simple approach is not available because the barcode actually includes different or additional characters which must be calculated from the barcode data. For example, the Code 128 barcode shown in the image below contains the same data as the Code 39 above.
Code 128 barcode
However, while the barcode still has start and stop bars, there is no correspondence between the characters in the data and the bars in the barcode. After the start bars the first pattern represents the pair of characters 12, and the next second pattern represent the pair 34. These two patterns are actualy the chararacters , and B in the Code 128 font. In addition Code 128 symbols must include a mandatory check character calculated from the data characters. In this case the check character is r. So the actual characters which were used to show the above symbol were ª,Br¬ - the ª and ¬ being the start and stop bars.
For 2D barcodes, such as Aztec, Datamatrix, PDF417 and QR Code, there are even more things added to the symbol, including finder patters and error correction characters.
So in most cases the conversion of a string of characters into barcode symbols requires both translation into patterns that are required by the barcode and the calculation of check characters. For this reason creating barcodes using barcode fonts usually requires a programming call to a library function.
For 1D barcodes there are two approaches to font barcodes. One is to have a barcode font for a specific barcode type (such as Code 39) - in which case the human readable code may be included under each character. Another is to have a font that supports a wide range of barcode types, but without the human readable form underneath - because different types require different bar patterns for a given human readable character. This latter approach is not really a disadvantage, as the data is generally available in text form to create the barcode in the first place, so it is not a problem to display or print this under the barcode.
The Barcode Fonts for Windows range of font packages provide fonts that (where applicable) include the human readable characters under the barcode, but a different font package is required for each barcode type, while the Universal Barcode Font package supports most common 1D & 2D barcodes, including postal and clocked codes, but only has human readable text under the bars for the 1D retail barcode types (GS1 8/12/13).
Some 2D barcodes may also be supported through 2D barcode fonts, although generally this approach can be used only with 2D types that have a consistent bar height. So Aztec, Databar, Datamatrix, PDF417, QR Code can be supported through fonts, while the Composite symbols cannot (because the symbols require rows of different heights). The Universal Barcode font kit also supports multiple barcode types.
Even barcode font products that support 2D types require that the application that will ultimately print or display the barcode allows for the selection of the font, the font size and the line spacing. Thus in Word and Access all these properties are available to the user and 2D font barcodes display and print correctly, while Excel does not permit the setting of a line spacing - thus preventing the printing of 2D barcodes directly from the worksheet without gaps between the lines! Excel can still be used for the storage of 2D font barcodes, but requires another application - such as Word's Mail merge - to print well-formed barcodes.
The dLSoft font products provide DLL, Active-X controls and .NET components for perfoming such translations. Barcode fonts are available for the following barcode types:
Most of the font products listed above include one or more DLLs which have functions such as:
ierr=dBarFont( icode, lpszin, lpszout, iflags);
where icode is an integer which represents the tyep of barcode required, lpszin is the data for the barcode (eg 1234), lpszout is a string which receives the barcode characters, and iflags is an integer that may contain values to indicate specific behavious - such as automatically calculating a check digit.
For 2D barcodes the conversion functions included addition parameters, such as
ierr=Bar2Ddmf(lpszIn, &n, &iflags, &imode, &isecurity, lpszOut); //example for Datamatrix symbol
where imode is a value that determines the mode of barcode (eg Square or Rectangular for Datamatrix, or QR Code or Micro QR for QR symbols), isecurity represent the desired amount of error correction to be built in to the symbol. the n parameter is normally left as 0, but can be used to specify the number of bytes in the data; this allows the library to encode pictures into barcodes (pictures usually contain some byte values of 0 which would otherwise terminate a string).
The DLLs also contain functions for generating output string directly on the clipboard, and for saving the string to a named file.
Many of the products listed above include Active-X controls suitable for placing of forms and reports for containers such as MS Access, .Net or Visual Basic. These permit the barcode properties to be set either programmatically or by displaying a Barcode Properties dialog.
The barcode data may be set as the Caption property and the output characters retrieved as the Output property.
The Active-X components may also be used with CreateObject. For example, the following code creates a QR Code object, initialises the Caption propery and returns the barcode characters for display in a text box:
Public qr1 As Object
Private Sub Form_Load()
Set qr1 = CreateObject("QROCX.QRocxCtrl.1")
abc.Caption = "Hello World"
Text2.Text = qr1.Output
The .Net components included with most of the above barcode font products may be added to the Visual Studio toolbox and used within VB.Net and C# projects. Properties may be set programmatically, eg dfont1.Caption="12345", and retrieved programmatically, eg textBox1.Text=dfont1.Barcode.
Printing from WinForms projects is readily accomplished in the PrintPage handler, eg.
Private Sub PrintDocument1_PrintPage(ByVal sender As
System.Object, ByVal e As
e.Graphics.PageUnit = GraphicsUnit.Document '
e.Graphics.DrawString(Dfont1.Barcode, Dfont1.Font, Brushes.Black, 300.0F, 300.0F)
' Indicate that this is the last page to print.
e.HasMorePages = False
Barcodes & Labels for Office includes an in-cell formula for placing a barcode directly into a cell on an Excel spreadsheet. A typical application would be to have column containing the barcode data and another column with the formula pasted down to generate the barcodes.
A typical formula would be in column b, row 2, =barcode(A2,9,0)
This would result in Code 128 barcodes appearing in column b.
All dLSoft products containing barcode fonts include the fonts as TTF and OTF, as well as Postscrip[t Type 1 and Type 3 formats. In most cases fonts are included in several thicknesses (to allow for ink-spread with some printing technologies), and height/width ratios.
For example, the Universal 1D barcode font contains the following fonts with the specified height/width ratios (values for the thinnest bar): UNA (50:1), UNB (33:1), UNC (25:1), UND (20:1), UNE (15:1), in addition to the UNF (33:1) clocked font. Each font is supplied full width (UNxW - wide font), 8% reduced (UNxR - reduced font), 16% reduced (UNxN - narrow font) and 25% reduced (UNxT - thin font).
There are many things to consider when deciding how best to implement barcodes. See our Barcode font or picture page for more thoughts.