.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Barcode::Code128 3pm" .TH Barcode::Code128 3pm "2022-12-11" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Barcode::Code128 \- Generate CODE 128 bar codes .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Barcode::Code128; \& \& $code = new Barcode::Code128; .Ve .SH "REQUIRES" .IX Header "REQUIRES" Perl 5.004, Carp, Exporter, \s-1GD\s0 (optional) .SH "EXPORTS" .IX Header "EXPORTS" By default, nothing. However there are a number of constants that represent special characters used in the \s-1CODE 128\s0 symbology that you may wish to include. For example if you are using the \s-1EAN\-128\s0 or \&\s-1UCC\-128\s0 code, the string to encode begins with the \s-1FNC1\s0 character. To encode the \s-1EAN\-128\s0 string \*(L"00 0 0012345 555555555 8\*(R", you would do the following: .PP .Vb 3 \& use Barcode::Code128 \*(AqFNC1\*(Aq; \& $code = new Barcode::Code128; \& $code\->text(FNC1.\*(Aq00000123455555555558\*(Aq); .Ve .PP To have this module export one or more of these characters, specify them on the \f(CW\*(C`use\*(C'\fR statement or use the special token ':all' instead to include all of them. Examples: .PP .Vb 2 \& use Barcode::Code128 qw(FNC1 FNC2 FNC3 FNC4 Shift); \& use Barcode::Code128 qw(:all); .Ve .PP Here is the complete list of the exportable characters. They are assigned to high-order \s-1ASCII\s0 characters purely arbitrarily for the purposes of this module; the values used do not reflect any part of the \s-1CODE 128\s0 standard. \fBWarning\fR: Using the \f(CW\*(C`CodeA\*(C'\fR, \f(CW\*(C`CodeB\*(C'\fR, \&\f(CW\*(C`CodeC\*(C'\fR, \f(CW\*(C`StartA\*(C'\fR, \f(CW\*(C`StartB\*(C'\fR, \f(CW\*(C`StartC\*(C'\fR, and \f(CW\*(C`Stop\*(C'\fR codes may cause your barcodes to be invalid, and be rejected by scanners. They are inserted automatically as needed by this module. .PP .Vb 4 \& CodeA 0xf4 CodeB 0xf5 CodeC 0xf6 \& FNC1 0xf7 FNC2 0xf8 FNC3 0xf9 \& FNC4 0xfa Shift 0xfb StartA 0xfc \& StartB 0xfd StartC 0xfe Stop 0xff .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Barcode::Code128 generates bar codes using the \s-1CODE 128\s0 symbology. It can generate images in \s-1PNG\s0 or \s-1GIF\s0 format using the \s-1GD\s0 package, or it can generate a text string representing the barcode that you can render using some other technology if desired. .PP The intended use of this module is to create a web page with a bar code on it, which can then be printed out and faxed or mailed to someone who will scan the bar code. The application which spurred its creation was an expense report tool, where the employee submitting the report would print out the web page and staple the receipts to it, and the Accounts Payable clerk would scan the bar code to indicate that the receipts were received. .PP The default settings for this module produce a large image that can safely be FAXed several times and still scanned easily. If this requirement is not important you can generate smaller image using optional parameters, described below. .PP If you wish to generate images with this module you must also have the \&\s-1GD\s0 module (written by Lincoln Stein, and available from \s-1CPAN\s0) installed. Using the libgd library, \s-1GD\s0 can generate files in \s-1PNG\s0 (Portable Network Graphics) or \s-1GIF\s0 (Graphic Interchange Format) formats. .PP Starting with version 1.20, and ending with 2.0.28 (released July 21st, 2004), \s-1GD\s0 and the underlying libgd library could not generate \&\s-1GIF\s0 files due to patent issues, but any modern version of libgd (since 2004) can do \s-1GIF\s0 as the patent has expired. Most browsers have no trouble with \s-1PNG\s0 files. .PP In order to ensure you have a sufficiently modern installation of the \&\s-1GD\s0 module to do both \s-1GIF\s0 and \s-1PNG\s0 formats, we require version 2.18 of \&\s-1GD\s0 (which in turn requires libgd 2.0.28) or higher. .PP If the \s-1GD\s0 module is not present, you can still use the module, but you will not be able to use its functions for generating images. You can use the \fBbarcode()\fR method to get a string of \*(L"#\*(R" and \*(L" \*(R" (hash and space) characters, and use your own image-generating routine with that as input. .PP To use the the \s-1GD\s0 module, you will need to install it along with this module. You can obtain it from the \s-1CPAN\s0 (Comprehensive Perl Archive Network) repository of your choice under the directory \&\f(CW\*(C`authors/id/LDS\*(C'\fR. Visit http://www.cpan.org/ for more information about \s-1CPAN.\s0 The \s-1GD\s0 home page is: http://stein.cshl.org/WWW/software/GD/GD.html .SH "METHODS" .IX Header "METHODS" .IP "new" 4 .IX Item "new" Usage: .Sp .Vb 1 \& $object = new Barcode::Code128 .Ve .Sp Creates a new barcode object. .IP "option" 4 .IX Item "option" Sets or retreives various options. If called with only one parameter, retrieves the value for that parameter. If called with more than one parameter, treats the parameters as name/value pairs and sets those option values accordingly. If called with no parameters, returns a hash consisting of the values of all the options (hash ref in scalar context). When an option has not been set, its default value is returned. .Sp You can also set or retrieve any of these options by using it as a method name. For example, to set the value of the padding option, you can use either of these: .Sp .Vb 2 \& $barcode\->padding(10); \& $barcode\->option("padding", 10); .Ve .Sp The valid options, and the default value and meaning of each, are: .Sp .Vb 10 \& width undef Width of the image (*) \& height undef Height of the image (*) \& border 2 Size of the black border around the barcode \& scale 2 How many pixels for the smallest barcode stripe \& font "large" Font (**) for the text at the bottom \& show_text 1 True/False: display the text at the bottom? \& font_margin 2 Pixels above, below, and to left of the text \& font_align "left" Align the text ("left", "right", or "center") \& transparent_text 1/0(***) True/False: use transparent background for text? \& top_margin 0 No. of pixels above the barcode \& bottom_margin 0 No. of pixels below the barcode (& text) \& left_margin 0 No. of pixels to the left of the barcode \& right_margin 0 No. of pixels to the right of the barcode \& padding 20 Size of whitespace before & after barcode .Ve .Sp * Width and height are the default values for the \f(CW$x\fR and \f(CW$y\fR arguments to the png, gif, or gd_image method (q.v.) .Sp ** Font may be one of the following: \*(L"giant\*(R", \*(L"large\*(R", \*(L"medium\*(R", \&\*(L"small\*(R", or \*(L"tiny\*(R". Or, it may be any valid \s-1GD\s0 font name, such as \&\*(L"gdMediumFont\*(R". .Sp *** The \*(L"transparent_text\*(R" option is \*(L"1\*(R" (true) by default for \s-1GIF\s0 output, but \*(L"0\*(R" (false) for \s-1PNG.\s0 This is because \s-1PNG\s0 transparency is not supported well by many viewing software The background color is grey (#CCCCCC) when not transparent. .IP "gif" 4 .IX Item "gif" .PD 0 .IP "png" 4 .IX Item "png" .IP "gd_image" 4 .IX Item "gd_image" .PD Usage: .Sp .Vb 3 \& $object\->png($text) \& $object\->png($text, $x, $y) \& $object\->png($text, { options... }) \& \& $object\->gif($text) \& $object\->gif($text, $x, $y) \& $object\->gif($text, { options... }) \& \& $object\->gd_image($text) \& $object\->gd_image($text, $x, $y) \& $object\->gd_image($text, { options... }) .Ve .Sp These methods generate an image using the \s-1GD\s0 module. The \fBgd_image()\fR method returns a \s-1GD\s0 object, which is useful if you want to do additional processing to it using the \s-1GD\s0 object methods. The other two create actual images. \s-1NOTE: GIF\s0 files require an old version of \&\s-1GD,\s0 and so you probably are not able to create them \- see below. .Sp The \fBgif()\fR and \fBpng()\fR methods are wrappers around \fBgd_image()\fR that create the \s-1GD\s0 object and then run the corresponding \s-1GD\s0 method to create output that can be displayed or saved to a file. Note that only one of these two methods will work, depending on which version of \s-1GD\s0 you have \- see below. The return value from \fBgif()\fR or \fBpng()\fR is a binary file, so if you are working on an operating system (e.g. Microsoft Windows) that makes a distinction between text and binary files be sure to call binmode(\s-1FILEHANDLE\s0) before writing the image to it, or the file may get corrupted. Example: .Sp .Vb 4 \& open(PNG, ">code128.png") or die "Can\*(Aqt write code128.png: $!\en"; \& binmode(PNG); \& print PNG $object\->png("CODE 128"); \& close(PNG); .Ve .Sp If you have \s-1GD\s0 version 1.20 or newer, the \s-1PNG\s0 file format is the only allowed option. Conversely if you have \s-1GD\s0 version prior to 1.20, then the \s-1GIF\s0 format is the only option. Check the \f(CW$object\fR\->\fBimage_format()\fR method to find out which you have (q.v.). .Sp Note: All of the arguments to this function are optional. If you have previously specified \f(CW$text\fR to the \f(CW\*(C`barcode()\*(C'\fR, \f(CW\*(C`encode()\*(C'\fR, or \&\f(CW\*(C`text()\*(C'\fR methods, you do not need to specify it again. The \f(CW$x\fR and \&\f(CW$y\fR variables specify the size of the barcode within the image in pixels. 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. See also the \&\f(CW$object\fR\->\fBwidth()\fR and \f(CW$object\fR\->\fBheight()\fR methods for another way of specifying this. .Sp If instead of specifying \f(CW$x\fR and \f(CW$y\fR, you pass a reference to a hash of name/value pairs, these will be used as the options, overriding anything set using the \f(CW$object\fR\->\fBoption()\fR (or width/height) method (q.v.). However, this will not set the options so any future barcodes using the same object will revert to the option list of the object. If you want to set the options permanently use the option, width, and/or height methods instead. .IP "barcode" 4 .IX Item "barcode" Usage: .Sp .Vb 1 \& $object\->barcode($text) .Ve .Sp 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 using \s-1GD\s0 to create the images. .Sp Note: The \f(CW$text\fR parameter is optional. If you have previously specified \f(CW$text\fR to the \f(CW\*(C`encode()\*(C'\fR or \f(CW\*(C`text()\*(C'\fR methods, you do not need to specify it again. .SS "Housekeeping Functions" .IX Subsection "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. .IP "encode" 4 .IX Item "encode" Usage: .Sp .Vb 3 \& $object\->encode \& $object\->encode($text) \& $object\->encode($text, $preferred_code) .Ve .Sp Do the encoding. If \f(CW$text\fR is supplied, will automatically call the \&\fBtext()\fR method to set that as the text value first. If \&\f(CW$preferred_code\fR is supplied, will try that code first. Otherwise, the codes will be tried in the following manner: .Sp 1. If it is possible to use Code C for any of the text, use that for as much of it as possible. .Sp 2. Check how many characters would be converted using codes A or B, and use that code to convert them. If the amount is equal, code A is used. .Sp 3. Repeat steps 1 and 2 until the text string has been completely encoded. .IP "text" 4 .IX Item "text" Usage: .Sp .Vb 2 \& $object\->text($text) \& $text = $object\->text .Ve .Sp Set or retrieve the text for this barcode. This will be called automatically by \fBencode()\fR or \fBbarcode()\fR so typically this will not be used directly by the user. .IP "start" 4 .IX Item "start" Usage: .Sp .Vb 1 \& $object\->start($code) .Ve .Sp If the code (see \fBcode()\fR) 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. .IP "stop" 4 .IX Item "stop" Usage: .Sp .Vb 1 \& $object\->stop() .Ve .Sp Computes the check character and appends it along with the Stop character, to the encoded string. Typically for internal use only. .IP "code" 4 .IX Item "code" Usage: .Sp .Vb 2 \& $object\->code($code) \& $code = $object\->code .Ve .Sp Set or retrieve the code for this barcode. \f(CW$code\fR may be 'A', 'B', or 'C'. Typically for internal use only. Not particularly meaningful unless called during the middle of encoding. .SH "CLASS VARIABLES" .IX Header "CLASS VARIABLES" None. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .ie n .IP "Unrecognized option ($opt) for $class" 4 .el .IP "Unrecognized option ($opt) for \f(CW$class\fR" 4 .IX Item "Unrecognized option ($opt) for $class" The specified option is not valid for the module. \f(CW$class\fR should be \&\*(L"Barcode::Code128\*(R" but if it has been inherited into another module, that module will show instead. \f(CW$opt\fR is the attempted option. .IP "The \fBgd_image()\fR method of Barcode::Code128 requires the \s-1GD\s0 module" 4 .IX Item "The gd_image() method of Barcode::Code128 requires the GD module" To call the \f(CW\*(C`gd_image()\*(C'\fR, \f(CW\*(C`png()\*(C'\fR, or \f(CW\*(C`gif()\*(C'\fR methods, the \s-1GD\s0 module must be present. This module is used to create the actual image. Without it, you can only use the \f(CW\*(C`barcode()\*(C'\fR method. .IP "Scale must be a positive integer" 4 .IX Item "Scale must be a positive integer" The scale factor for the \f(CW\*(C`gd_image()\*(C'\fR, \f(CW\*(C`png()\*(C'\fR, or \f(CW\*(C`gif()\*(C'\fR methods must be a positive integer. .IP "Border ($border) must be a positive integer or zero" 4 .IX Item "Border ($border) must be a positive integer or zero" The border option cannot be a fractional or negative number. .ie n .IP "Invalid font $font" 4 .el .IP "Invalid font \f(CW$font\fR" 4 .IX Item "Invalid font $font" The specified font is not valid. Note that this is tested using \&\s-1GD\-\s0>\fBcan()\fR, and so any subroutine in \s-1GD\s0.pm will pass this test \- but only the fonts will actually work. See the \s-1GD\s0 module documentation for more. .ie n .IP "Image width $x is too small for bar code" 4 .el .IP "Image width \f(CW$x\fR is too small for bar code" 4 .IX Item "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 \f(CW\*(C`gd_image()\*(C'\fR, \f(CW\*(C`png()\*(C'\fR, or \f(CW\*(C`gif()\*(C'\fR and it will use the minimum. .ie n .IP "Image height $y is too small for bar code" 4 .el .IP "Image height \f(CW$y\fR is too small for bar code" 4 .IX Item "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 \f(CW\*(C`gd_image()\*(C'\fR, \f(CW\*(C`png()\*(C'\fR, or \f(CW\*(C`gif()\*(C'\fR and it will use the minimum. .ie n .IP "Unable to create $x x $y image" 4 .el .IP "Unable to create \f(CW$x\fR x \f(CW$y\fR image" 4 .IX Item "Unable to create $x x $y image" An error occurred when initializing a GD::Image object for the specified size. Perhaps \f(CW$x\fR and \f(CW$y\fR are too large for memory? .IP "The \fBgif()\fR method of Barcode::Code128 requires the \s-1GD\s0 module" 4 .IX Item "The gif() method of Barcode::Code128 requires the GD module" .PD 0 .IP "The \fBgif()\fR method of Barcode::Code128 requires version less than 1.20 of \s-1GD\s0" 4 .IX Item "The gif() method of Barcode::Code128 requires version less than 1.20 of GD" .IP "The \fBpng()\fR method of Barcode::Code128 requires the \s-1GD\s0 module" 4 .IX Item "The png() method of Barcode::Code128 requires the GD module" .IP "The \fBpng()\fR method of Barcode::Code128 requires at least version 1.20 of \s-1GD\s0" 4 .IX Item "The png() method of Barcode::Code128 requires at least version 1.20 of GD" .PD These errors indicate that the \s-1GD\s0 module, or the correct version of the \s-1GD\s0 module for this method, was not present. You need to install \&\s-1GD\s0 version 1.20 or greater to create \s-1PNG\s0 files, or a version of \s-1GD\s0 less than 1.20 to create \s-1GIF\s0 files. .IP "No encoded text found" 4 .IX Item "No encoded text found" This message from \f(CW\*(C`barcode()\*(C'\fR 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. This error occurs when you are trying to create a barcode by calling one of \f(CW\*(C`gd_image()\*(C'\fR, \&\f(CW\*(C`png()\*(C'\fR, \f(CW\*(C`gif()\*(C'\fR, or \f(CW\*(C`barcode()\*(C'\fR without having specified the text to be encoded. .IP "No text defined" 4 .IX Item "No text defined" This message from \f(CW\*(C`encode()\*(C'\fR 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. .IP "Invalid preferred code ``$preferred_code''" 4 .IX Item "Invalid preferred code ``$preferred_code''" This error means \f(CW\*(C`encode()\*(C'\fR was called with the \f(CW$preferred_code\fR optional parameter but it was not one of ``A'', ``B'', or ``C''. .IP "Sanity Check Overflow" 4 .IX Item "Sanity Check Overflow" This is a serious error in \f(CW\*(C`encode()\*(C'\fR 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. .IP "Unable to find encoding for ``$text''" 4 .IX Item "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 \s-1CODE 128\s0 character set, such as a character with an \s-1ASCII\s0 value higher than 127 (except the special control characters defined in this module). .IP "Unable to switch from ``$old_code'' to ``$new_code''" 4 .IX Item "Unable to switch from ``$old_code'' to ``$new_code''" This is a serious error in \f(CW\*(C`start()\*(C'\fR that indicates a serious problem occurred when switching between the codes (A, B, or C) of \s-1CODE 128.\s0 If you get this error please contact the author. .IP "Unable to start with ``$new_code''" 4 .IX Item "Unable to start with ``$new_code''" This is a serious error in \f(CW\*(C`start()\*(C'\fR that indicates a serious problem occurred when starting encoding in one of the codes (A, B, or C) of \&\s-1CODE 128.\s0 If you get this error please contact the author. .IP "Unknown code ``$new_code'' (should be A, B, or C)" 4 .IX Item "Unknown code ``$new_code'' (should be A, B, or C)" This is a serious error in \f(CW\*(C`code()\*(C'\fR that indicates an invalid argument was supplied. Only the codes (A, B, or C) of \s-1CODE 128\s0 may be supplied here. If you get this error please contact the author. .SH "BUGS" .IX Header "BUGS" At least some Web browsers do not seem to handle \s-1PNG\s0 files with transparent backgrounds correctly. As a result, the default for \s-1PNG\s0 is to generate barcodes without transparent backgrounds \- the background is grey instead. .SH "AUTHOR" .IX Header "AUTHOR" William R. Ward, wrw@bayview.com .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1), \s-1GD\s0