Barcodes on UNIX

The report writer interfaces with the printer driver using barcode scripts. A barcode script saves the cursor position, prints a barcode with a given height, and returns to the saved cursor position. These scripts must be available in the barcode_dir directory. This directory is relative to $BSE/lib/barcode, therefore, if barcode_dir = hp_barcode, the bar-code directory is $BSE/lib/barcode/hp_barcode. Bar-code scripts are prefixed by the word type and suffixed by a two-digit number, for example:

type01.

The following example shows a bar-code script, which saves the cursor position and restores the cursor after the barcode is printed. You can only implement barcodes if this type of scheme is permitted. Note that sending escape codes to a printer is device-specific. For more information, see your printer manufacturer's documentation.

#!/bin/sh 
#
# Sample driver for HP Laserjet 4
# with "Barcodes & More Font Cartridge"
#
# Prints EAN/UPC with the code under it.
# $1 means the barcode
# $2 means the height of the barcode (number of lines)
# 
code=$1
height=$2 
Push()
{
# push cursor position (max 20x)
echo "\033&f0S\c"
} 
Pop()
{
# pop cursor position
echo "\033&f1S\c"
} 
NextRow()
{
# move to next row, relative
echo "\033&a+1R\c"
} 
# – save cursor position – filter assumes same pos. after barcode print
Push 
str1=`echo $code | awk '{print substr($1, 1, 5)}'`
str2=`echo $code | awk '{print substr($1, 6, 5)}'` 
# – select EAN/UPC 13 mil font
echo "\033(8Y\033(s1p12v0s3b0T\c" 
while [$height –gt 1]
do
Push
echo "($str1-$str2(\c"
Pop
NextRow
height=`expr $height – 1`
done 
# – last (empty) line of barcode
Push
echo "(- (\c"
Pop 
# – select Courier 12cpi.
echo "\033(10U\033(s0p12.00h10.0v0s0b3T\c" 
# – move x+25 dots
echo "\033*p+25X\c" 
# – print code (text)
echo "$str1 $str2\c" 
# – restore cursor position for filter
Pop 
exit 0