NAME

Barcode::Code128 - Generate CODE 128 bar codes

SYNOPSIS

use Barcode::Code128;

$code = new Barcode::Code128;

REQUIRES

Perl 5.004, Carp, Exporter, GD

EXPORTS

By default, nothing. However there are a number of constants that represent special characters used in the CODE 128 symbology that you may wish to include. For example if you are using the EAN-128 or UCC-128 code, the string to encode begins with the FNC1 character. To encode the EAN-128 string "00 0 0012345 555555555 8", you would do the following:

use Barcode::Code128 'FNC1';
$code = new Barcode::Code128;
$code->text(FNC1.'00000123455555555558');

To have this module export one or more of these characters, specify them on the use statement or use the special token ':all' instead to include all of them. Examples:

use Barcode::Code128 qw(FNC1 FNC2 FNC3 FNC4 Shift);
use Barcode::Code128 qw(:all);

Here is the complete list of the exportable characters. They are assigned to high-order ASCII characters purely arbitrarily for the purposes of this module; the values used do not reflect any part of the CODE 128 standard. Warning: Using the CodeA, CodeB, CodeC, StartA, StartB, StartC, and Stop codes may cause your barcodes to be invalid, and be rejected by scanners. They are inserted automatically as needed by this module.

CodeA      0xf4        CodeB      0xf5         CodeC      0xf6
FNC1       0xf7        FNC2       0xf8         FNC3       0xf9
FNC4       0xfa        Shift      0xfb         StartA     0xfc
StartB     0xfd        StartC     0xfe         Stop       0xff

DESCRIPTION

Barcode::Code128 generates bar codes using the CODE 128 symbology. The typical use this is for generating a GIF file with the gif() method which uses the GD package by Lincoln Stein. When this GIF file is printed, it can be scanned by most modern hand-held bar code readers. The application which drove the invention of this module places the GIF file on a web page which the user must print out and submit along with supporting documents. The bar code helps the receiving agency record when it has been received.

Since the GD module is required you will need to install it before installing this module. You can obtain it from the CPAN (Comprehensive Perl Archive Network) repository of your choice under the directory authors/id/LDS. Visit http://www.perl.com/ for more information about CPAN. The GD home page is: http://stein.cshl.org/WWW/software/GD/GD.html

METHODS

$object = new Barcode::Code128

Creates a new barcode object.

$object->gif($text)
$object->gif($text, $x, $y)

Generate a GIF file and return it. Typically you will either print the result to standard output or save it to a file. The contents of the return value from this method are a binary file, so if you are working on an operating system that makes a distinction between text and binary files be sure to call binmode(FILEHANDLE) before writing the GIF to it. Example:

open(GIF, ">code128.gif") or die "Can't write code128.gif: $!\n";
binmode(GIF);
print GIF $object->gif("CODE 128");
close(GIF);

Note: All of the arguments to this function are optional. If you have previously specified $text to the barcode(), encode(), or text() methods, you do not need to specify it again. The $x and $y variables specify the size of the barcode within GIF file in pixels. The overall image will be an extra 20 pixels taller to accomodate the plaintext rendering of the encoded message (in black on a transparent background). If size(s) are not specified, they will be set to the minimum size, which is the length of the barcode plus 40 pixels horizontally, and 15% of the length of the barcode vertically.

$object->barcode($text)

Computes the bar code for the specified text. The result will be a string of '#' and space characters representing the dark and light bands of the bar code. You can use this if you have an alternate printing system besides the gif() method.

Note: The $text parameter is optional. If you have previously specified $text to the encode() or text() methods, you do not need to specify it again.

Housekeeping Functions

The rest of the methods defined here are only for internal use, or if you really know what you are doing. Some of them may be useful to authors of classes that inherit from this one, or may be overridden by subclasses. If you just want to use this module to generate bar codes, you can stop reading here.

$object->encode
$object->encode($text)

Do the encoding. If $text is supplied, will automatically call the text() method to set that as the text value first.

$object->text($text)
$text = $object->text

Set or retrieve the text for this barcode. This will be called automatically by encode() or barcode() so typically this will not be used directly by the user.

$object->start($code)

If the code (see code()) is already defined, then adds the CodeA, CodeB, or CodeC character as appropriate to the encoded message inside the object. Typically for internal use only.

$object->stop()

Computes the check character and appends it along with the Stop character, to the encoded string. Typically for internal use only.

$object->code($code)
$code = $object->code

Set or retrieve the code for this barcode. $code may be 'A', 'B', or 'C'. Typically for internal use only. Not particularly meaningful unless called during the middle of encoding.

CLASS VARIABLES

None.

DIAGNOSTICS

Image width $x is too small for bar code

You have specified an image width that does not allow enough space for the bar code to be displayed. The minimum allowable is the size of the bar code itself plus 40 pixels. If in doubt, just omit the width value when calling gif() and it will use the minimum.

Image height $y is too small for bar code

You have specified an image height that does not allow enough space for the bar code to be displayed. The minimum allowable is 15% of the width of the bar code. If in doubt, just omit the height value when calling gif() and it will use the minimum.

Unable to create $x x $y GIF image

An error occurred when initializing a GD::Image object for the specified size. Perhaps $x and $y are too large for memory?

No encoded text found

This message from barcode() typically means that there was no text message supplied either during the current method call or in a previous method call on the same object.

No text defined

This message from encode() typically means that there was no text message supplied either during the current method call or in a previous method call on the same object.

Unable to find encoding for ``$text''

Part or all of the message could not be encoded. This may mean that the message contained characters not encodable in the CODE 128 character set, such as a character with an ASCII value higher than 127 (except the special control characters defined in this module).

Sanity Check Overflow

This is a serious error in encode() that indicates a serious problem attempting to encode the requested message. This means that an infinite loop was generated. If you get this error please contact the author.

Unable to switch from ``$old_code'' to ``$new_code''

This is a serious error in start() that indicates a serious problem occurred when switching between the codes (A, B, or C) of CODE 128. If you get this error please contact the author.

Unable to start with ``$new_code''

This is a serious error in start() that indicates a serious problem occurred when starting encoding in one of the codes (A, B, or C) of CODE 128. If you get this error please contact the author.

Unknown code ``$new_code'' (should be A, B, or C)

This is a serious error in code() that indicates an invalid argument was supplied. Only the codes (A, B, or C) of CODE 128 may be supplied here. If you get this error please contact the author.

AUTHOR

William R. Ward, wrw@bayview.com

SEE ALSO

perl(1), GD