NAME
PDF::Reuse::Barcode - Create barcodes for PDF documents with PDF::Reuse and GD::Barcode
SYNOPSIS
use PDF::Reuse;
use PDF::Reuse::Barcode;
use strict;
prFile('bars.pdf');
PDF::Reuse::Barcode::ITF (x => 70,
y => 530,
value => '0123456789',
prolong => 2.96);
prEnd();
DESCRIPTION
This is a sub-module to PDF::Reuse. It creates barcode "images" to be used in PDF documents. It uses GD::Barcode and its sub-modules: GD::Barcode::Code39, COOP2of5, EAN13 and so on, to calculate the barcode pattern. Normally the barcodes are displayed on a white background and with the characters under the bars. You can rotate the "image", make it smaller or bigger, prolong the bars and change the background. (But then, don't forget to test that your barcode reader still understands it.)
If you don't change the size of the "image", the bars are approximately 24 pixels high (the guard bars a few pixels longer) and the box/background is 38 pixels high and something like 20 pixels wider than the barcodes. The text under the bars are 10 pixels high.
FUNCTIONS
All functions are called in a similar way. Just replace 'ITF' in the example under SYNOPSIS with some other function name and let the value parameter follow the rules of that function.
Code39
Translates the characters 0-9, A-Z, '-', '*', '+', '$', '%', '/', '.' and ' ' to a barcode pattern
COOP2of5
Creates COOP2of5 barcodes from a string consisting of the numeric characters 0-9
EAN13
Creates EAN13 barcodes from a string of 12 or 13 digits. The check number (the 13:th digit) is calculated if not supplied. If there is given check number it is not controlled.
EAN8
Translates a string of 7 or 8 digits to EAN8 barcodes. The check number (the 8:th digit) is calculated if not supplied. If there is given check number it is not controlled.
IATA2of5
Creates IATA2of5 barcodes from a string consisting of the numeric characters 0-9
Industrial2of5
Creates Industrial2of5 barcodes from a string consisting of the numeric characters 0-9
ITF
Translates the characters 0-9 to a barcodes. These barcodes could also be called 'Interleaved2of5'.
Matrix2of5
Creates Matrix2of5 barcodes from a string consisting of the numeric characters 0-9
NW7
Creates a NW7 barcodes from a string consisting of the numeric characters 0-9
UPCA
Translates a string of 11 or 12 digits to UPCA barcodes. The check number (the 12:th digit) is calculated if not supplied. If there is given check number it is not controlled.
UPCE
Translates a string of 6, 7 or 8 digits to UPCE barcodes. If the string is 6 digits long, '0' is added first in the string. The check number (the 8:th digit) is calculated if not supplied. If there is given check number it is not controlled.
COMMON PARAMETERS
All functions accepts these parameters. The parameters should be put in a hash. All of them are optional, except 'value'.
value
A string of characters which will be translated to barcodes.
x
Number of pixels along the x-axis where to put the lower left "corner" of the barcode image.
y
Number of pixels along the y-axis where to put the lower left "corner" of the barcode image.
size
A (decimal) number. If you define a number for this parameter, all sizes along the x- and y-axes will multiplied by this number. Also the text under the bars will be scaled.
xSize
A (decimal) number. If you define a number for this parameter, all sizes along the x-axis will multiplied by this number. The text under the bars are also affected.
ySize
A (decimal) number. If you define a number for this parameter, all sizes along the y-axis will multiplied by this number. The text under the bars are also affected.
prolong
0 or a decimal number greater than 1. Prolongs the bars with this factor. In reality tells the module to prolong the bars by repeatedly rewriting the barcode pattern.
text
Normally this parameter is 'yes', which will cause the digits to be written as text under the barcodes. If this parameter is '' or 0, the text will be suppressed.
drawBackground
By default this parameter is 1, which will cause the barcodes to be drawn on a prepared background. If this parameter is '' or 0, the current background will be used, and the module will not try change it.
background
Normally it is '1 1 1', which will draw a white background/box around the barcodes. Choose another RGB-combination if you want another color.
rotate
A degree to rotate the barcode image counter-clockwise
EXAMPLE
use PDF::Reuse;
use PDF::Reuse::Barcode;
use strict;
prFile('bars.pdf');
#################################################################
# First a rectangle is drawn in the upper part of the page
#################################################################
my $str = "q\n"; # save the graphic state
$str .= "0.9 0.5 0.5 rg\n"; # a fill color
$str .= "10 400 440 410 re\n"; # a rectangle
$str .= "b\n"; # fill (and a little more)
$str .= "Q\n"; # restore the graphic state
prAdd($str);
#################################
# An image with prolonged bars,
#################################
PDF::Reuse::Barcode::ITF (x => 50,
y => 700,
value => '0123456789',
prolong => 2.96);
#############################
# A magnified barcode image
#############################
PDF::Reuse::Barcode::EAN13 (x => 250,
y => 700,
value => '012345678901',
size => 1.5);
######################################################
# A barcode image magnified a little along the y-axis
######################################################
PDF::Reuse::Barcode::EAN8 (x => 150,
y => 500,
value => '0123456',
ySize => 1.2);
################################
# With the box in a light color
################################
PDF::Reuse::Barcode::Code39 (x => 70,
y => 300,
value => 'THIS IS SOMETHING',
background => '0.99 0.97 0.97');
#############################################
# With everything expanded along the x-axis
#############################################
PDF::Reuse::Barcode::NW7 (x => 70,
y => 100,
value => '012345678901',
xSize => 2);
#################################################
# An image, 90 degrees rotated, might look
# strange on the screen, should be ok as printed
#################################################
PDF::Reuse::Barcode::UPCA (x => 400,
y => 100,
value => '12345678901',
drawBackground => 0,
rotate => 90);
prEnd();
LIMITATION
EAN13, EAN8, UPCA and UPCE have "guard" bars. These, a little longer bars, are often a little blurred at the lower ends when they are displayed on a screen. If you magnify the image, the lines are displayed correctly. When you print the image there shouldn't be any problem, if you use at least 600 dpi.
Also rotated barcodes might look strange on a screen. Most often they are much better as printed on paper. Try to use "size" rather than "prolong", when you have a rotated barcode "image". (If it has been rotated 90 or 270 degrees, you can make the bars longer with the help of xSize.)
SEE ALSO
These modules are used for calculation of the barcode pattern
GD::Barcode
GD::Barcode::Code39
GD::Barcode::COOP2of5
GD::Barcode::EAN13
GD::Barcode::EAN8
GD::Barcode::IATA2of5
GD::Barcode::Industrial2of5
GD::Barcode::ITF
GD::Barcode::Matrix2of5
GD::Barcode::NW7
GD::Barcode::UPCA
GD::Barcode::UPCE
AUTHOR
Lars Lundberg, elkelund@worldonline.se
COPYRIGHT
Copyright (C) 2003 Lars Lundberg, Solidez HB. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
DISCLAIMER
You get this module free as it is, but nothing is guaranteed to work, whatever implicitly or explicitly stated in this document, and everything you do, you do at your own risk - I will not take responsibility for any damage, loss of money and/or health that may arise from the use of this module!