Barcode(3pm)

๐Ÿ“ฆ
version 0.09 ยท 4 versions
, in ubuntu resolute, ubuntu stonking

๐Ÿ’– Barcode(3pm) ๐Ÿ’–

User Contributed Perl Documentation โ€” yes bestie, it's a 3pm page, that's the manual name, and it's giving perl module energy โœจ


๐ŸŒธ NAME ๐ŸŒธ

PDF::Reuse::Barcode โ€” Create barcodes for PDF documents with PDF::Reuse ๐ŸŽ€


โœจ 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();

Like, that's the whole vibe right there. Load it, name a file, draw a barcode, close it. Slay. ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Okay so this is a sub-module to PDF::Reuse. Its whole job? Making barcode "images" that you can drop into PDF documents. It leans on GD::Barcode and its little sub-module babies โ€” GD::Barcode::Code39, COOP2of5, EAN13 and so on โ€” to work out the barcode pattern. For Code128 it uses Barcode::Code128 instead. ๐Ÿซถ

By default, barcodes show up on a white background with the characters sitting under the bars. You can rotate the "image", make it smaller or bigger, prolong the bars, and change the background. (But bestie, don't forget to test that your barcode scanner still understands it. Fr fr. ๐Ÿ˜ญ)

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 is 10 pixels high. ๐Ÿ“


๐Ÿ”ฅ FUNCTIONS ๐Ÿ”ฅ

All functions are called in a similar way. Just swap 'ITF' in the example under SYNOPSIS for some other function name, and let the value parameter follow the rules of that function. One shape, many barcodes. Iconic. ๐Ÿ‘‘

๐ŸŒˆ Code128 ๐ŸŒˆ

Creates Code128 barcodes with the help of Barcode::Code128. Go look at that module for further info, iykyk. ๐Ÿ‘€

# code128.pl

use PDF::Reuse;
use PDF::Reuse::Barcode;
prFile('code128.pdf');
PDF::Reuse::Barcode::Code128(x     => 100,
                             y     => 730,
                             value => '00000123455555555558');
prEnd();

The constants CodeA, FNC1, SHIFT and so on are not imported, but if you really need them (??), try using the character values instead. ๐Ÿ™ˆ

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

# Instead of FCN1

use PDF::Reuse;
use PDF::Reuse::Barcode;
prFile('unusual.pdf');
PDF::Reuse::Barcode::Code128(x     => 100,
                             y     => 430,
                             value => chr(0xf7) . '00000123455555555558',
                             text  => 0 );

 # Font and font size has to be chosen
 # Text could be put manually at x => 110
 #                               y => 431
 # The size, xSize, ySize and rotation doesn't influence the text
 # in this case ...

prEnd();

Not me reading that comment block three times. It's fine. It's all fine. ๐Ÿ’€

๐ŸŽ€ Code39 ๐ŸŽ€

Translates the characters 0-9, A-Z, '-', '*', '+', '$', '%', '/', '.' and ' ' into a barcode pattern. ๐Ÿฆ‹

In Code39, the asterisk is the start and stop bar, but PDF::Reuse::Barcode expects you to supply the asterisks. If you don't want them showing up in the text version, pass the option hide_asterisk, like this:

PDF::Reuse::Barcode::Code39 (x             => 10,
                             y             => 20,
                             value         => '*62002*',
                             hide_asterisk => 1);

๐ŸŒธ 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 a 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 a 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 barcodes. These barcodes could also be called 'Interleaved2of5'. ๐Ÿ‘‘

๐ŸŒˆ Matrix2of5 ๐ŸŒˆ

Creates Matrix2of5 barcodes from a string consisting of the numeric characters 0-9. ๐Ÿ”ข

๐ŸŽ€ NW7 ๐ŸŽ€

Creates NW7 barcodes from a string consisting of the numeric characters 0-9. ๐Ÿ”ข

๐Ÿฆ‹ QRcode ๐Ÿฆ‹

Creates QRcodes from numeric, alphanumeric, binary or Kanji data โ€” or a mixture of these. Main character energy, honestly. โœจ

๐Ÿ‘‘ 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 a 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 a given check number, it is not controlled. โš ๏ธ


๐Ÿ’ซ COMMON PARAMETERS ๐Ÿ’ซ

Every function accepts these parameters. Put them in a hash, bestie. All of them are optional โ€” except 'value'. That one's mandatory, no cap. ๐Ÿซถ

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 be multiplied by this number. Also the text under the bars will be scaled. ๐Ÿ“

For QRcodes, the square of this number determines the number of 'modulesize' rectangles used to represent a single module โ€” so 1=1, 2=4, 3=9, etc. ๐Ÿงฎ

xSize

A (decimal) number. If you define a number for this parameter, all sizes along the x-axis will be multiplied by this number. The text under the bars is also affected. โ†”๏ธ

ySize

A (decimal) number. If you define a number for this parameter, all sizes along the y-axis will be multiplied by this number. The text under the bars is also affected. โ†•๏ธ

prolong

0 or a decimal number greater than 1. Prolongs the bars with this factor. In reality it tells the module to prolong the bars by repeatedly rewriting the barcode pattern. ๐Ÿช„

text

Normally this parameter is 'yes', which causes the digits to be written as text under the barcodes. If this parameter is '' or 0, the text gets suppressed. ๐Ÿคซ

drawbackground

By default this parameter is 1, which causes the barcodes to be drawn on a prepared background. If this parameter is '' or 0, the current background will be used, and the module won't try to change it. ๐ŸŽจ

For QRcodes, this will use the 'graybackground' color to draw a rectangle including the "quiet zone" around the QRcode. โฌœ

background

Normally it is '1 1 1', which draws a white background/box around the barcodes. Choose another RGB-combination if you want another color. ๐ŸŒˆ

For QRcodes, see 'graybackground'. ๐Ÿ‘€

rotate

A degree to rotate the barcode image counter-clockwise. ๐Ÿ”„


๐ŸŒŸ QRCODE SPECIFIC PARAMETERS ๐ŸŒŸ

When generating QRcodes, some of the common parameters get ignored, and some QRcode-specific parameters are available for modifying features of the QRcode. QRcodes are generated with a Gray colorspace. ๐Ÿฉถ

graybackground

Normally it is 1, which draws a white background/box around the QRcodes. Choose another value between 0 and 1 (inclusive) to specify a different shade of gray for the background. ๐ŸŒซ๏ธ

modulesize

Defaults to 1. Sets the size in Postscript points of the rectangle drawn for a single rectangle when drawing a QRcode. ๐Ÿ“

qr_ecc

Defaults to 'M'. Sets the error correction mode for the QRcode and can be set to L (Low), M (Medium), Q (Quartile), or H (High). ๐Ÿ›ก๏ธ

qr_version

Defaults to 1. Set to an integer value from 1 to 40 to select the size and data capacity of the QRcode. ๐Ÿ”ข

qr_padding

Defaults to 0. Sets an amount of padding to insert between modules in the QRcode (may be useful if prints do not scan well). ๐Ÿงฉ


okay that's part 1, don't go anywhere bestie, there's more ๐Ÿ’œ

โœจ EXAMPLE โœจ

okay bestie, here's a whole entire vibe. this example draws a rectangle, then yeets a bunch of different barcodes onto the page. copy it, run it, live your truth ๐Ÿ’–

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',
                             hide_asterisk => 1);

#############################################
# 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);

#################################################
# A QRcode with a 10% gray "quiet zone"
#################################################

PDF::Reuse::Barcode::QRcode (x              => 300,
                             y              => 500,
                             value          => 'http://example.org/',
                             drawbackground => 1,
                             graybackground => 0.9, # 10% gray
                             qr_version     => 2,
                             modulesize     => 2);
prEnd();

๐Ÿ˜ญ LIMITATION ๐Ÿ˜ญ

so EAN13, EAN8, UPCA and UPCE have these little "guard" bars โ€” the ones that stick out a lil longer than the rest. and when you're staring at them on a screen, those longer bars are often a little blurry at the bottom ends. it's giving "why is my barcode fuzzy" energy ๐Ÿ’€

  • magnify the image and the lines render correctly, promise
  • printing it? no problem at all, as long as you use at least 600 dpi
  • also rotated barcodes might look weird on a screen. most often they look wayyy better printed on paper. when you have a rotated barcode "image", try to use size instead of prolong. and if it's 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, iykyk:

  • Barcode::Code128
  • 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::QRcode
  • GD::Barcode::UPCA
  • GD::Barcode::UPCE

๐Ÿซถ AUTHOR ๐Ÿซถ

Lars Lundberg, larslund@cpan.org Chris Nighswonger, cnighs@cpan.org


๐Ÿ’– THANKS TO ๐Ÿ’–

Everyone who has helped me with corrections and ideas, Martin Langhoff among others. And of course credits to Kawai Takanori and William R. Ward who have written the modules for calculating the barcode patterns. absolute icons, no cap โœจ


Copyright (C) 2003 - 2009 Lars Lundberg, Solidez HB. All rights reserved. Copyright (C) 2010 - 2014 Chris Nighswonger

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt ๐Ÿ’…


๐Ÿ’€ 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!

bestie pls read that one again. nothing is guaranteed. you do it at your own risk. it's giving "no promises" ๐Ÿ˜ญ

and that's the whole page, babes ๐ŸŒธ this was Barcode(3pm) from perl v5.40.1, dated 2026-01-25 โ€” go forth and generate some gorgeous barcodes, you're the main character of this PDF ๐Ÿ’œ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from