Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

Author: Nicola Asuni
Version: 1.0.027
File Size: 2357 lines (73 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: TCPDFBarcode  - X-Ref


__construct($code, $type)   X-Ref
This is the class constructor.
Return an array representations for common 1D barcodes:<ul>
<li>$arrcode['code'] code to be printed on text label</li>
<li>$arrcode['maxh'] max barcode height</li>
<li>$arrcode['maxw'] max barcode width</li>
<li>$arrcode['bcode'][$k] single bar or space in $k position</li>
<li>$arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.</li>
<li>$arrcode['bcode'][$k]['w'] bar width in units.</li>
<li>$arrcode['bcode'][$k]['h'] bar height in units.</li>
<li>$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)</li></ul>

param: $code (string) code to print
param: $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extension</li><li>EAN5 : 5-Digits UPC-Based Extension</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>

getBarcodeArray()   X-Ref
Return an array representations of barcode.

return: array

getBarcodeSVG($w=2, $h=30, $color='black')   X-Ref
Send barcode as SVG image object to the standard output.

param: $w (int) Minimum width of a single bar in user units.
param: $h (int) Height of barcode in user units.
param: $color (string) Foreground color (in SVG format) for bar elements (background is transparent).

getBarcodeSVGcode($w=2, $h=30, $color='black')   X-Ref
Return a SVG string representation of barcode.

return: string SVG code.
param: $w (int) Minimum width of a single bar in user units.
param: $h (int) Height of barcode in user units.
param: $color (string) Foreground color (in SVG format) for bar elements (background is transparent).

getBarcodeHTML($w=2, $h=30, $color='black')   X-Ref
Return an HTML representation of barcode.

return: string HTML code.
param: $w (int) Width of a single bar element in pixels.
param: $h (int) Height of a single bar element in pixels.
param: $color (string) Foreground color for bar elements (background is transparent).

getBarcodePNG($w=2, $h=30, $color=array(0,0,0)   X-Ref
Send a PNG image representation of barcode (requires GD or Imagick library).

param: $w (int) Width of a single bar element in pixels.
param: $h (int) Height of a single bar element in pixels.
param: $color (array) RGB (0-255) foreground color for bar elements (background is transparent).

getBarcodePngData($w=2, $h=30, $color=array(0,0,0)   X-Ref
Return a PNG image representation of barcode (requires GD or Imagick library).

return: image or false in case of error.
param: $w (int) Width of a single bar element in pixels.
param: $h (int) Height of a single bar element in pixels.
param: $color (array) RGB (0-255) foreground color for bar elements (background is transparent).

setBarcode($code, $type)   X-Ref
Set the barcode.

return: array barcode array
param: $code (string) code to print
param: $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extension</li><li>EAN5 : 5-Digits UPC-Based Extension</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>IMBPRE: Pre-processed Intelligent Mail Barcode - Onecode - USPS-B-3200, using only F,A,D,T letters</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>

barcode_code39($code, $extended=false, $checksum=false)   X-Ref
CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
General-purpose code in very wide use world-wide

return: array barcode representation.
param: $code (string) code to represent.
param: $extended (boolean) if true uses the extended mode.
param: $checksum (boolean) if true add a checksum to the code.

encode_code39_ext($code)   X-Ref
Encode a string to be used for CODE 39 Extended mode.

return: encoded string.
param: $code (string) code to represent.

checksum_code39($code)   X-Ref
Calculate CODE 39 checksum (modulo 43).

return: char checksum.
param: $code (string) code to represent.

barcode_code93($code)   X-Ref
CODE 93 - USS-93
Compact code similar to Code 39

return: array barcode representation.
param: $code (string) code to represent.

checksum_code93($code)   X-Ref
Calculate CODE 93 checksum (modulo 47).

return: string checksum code.
param: $code (string) code to represent.

checksum_s25($code)   X-Ref
Checksum for standard 2 of 5 barcodes.

return: int checksum.
param: $code (string) code to process.

barcode_msi($code, $checksum=false)   X-Ref
MSI.
Variation of Plessey code, with similar applications
Contains digits (0 to 9) and encodes the data only in the width of bars.

return: array barcode representation.
param: $code (string) code to represent.
param: $checksum (boolean) if true add a checksum to the code (modulo 11)

barcode_s25($code, $checksum=false)   X-Ref
Standard 2 of 5 barcodes.
Used in airline ticket marking, photofinishing
Contains digits (0 to 9) and encodes the data only in the width of bars.

return: array barcode representation.
param: $code (string) code to represent.
param: $checksum (boolean) if true add a checksum to the code

binseq_to_array($seq, $bararray)   X-Ref
Convert binary barcode sequence to TCPDF barcode array.

return: array barcode representation.
param: $seq (string) barcode as binary sequence.
param: $bararray (array) barcode array.

barcode_i25($code, $checksum=false)   X-Ref
Interleaved 2 of 5 barcodes.
Compact numeric code, widely used in industry, air cargo
Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.

return: array barcode representation.
param: $code (string) code to represent.
param: $checksum (boolean) if true add a checksum to the code

barcode_c128($code, $type='')   X-Ref
C128 barcodes.
Very capable code, excellent density, high reliability; in very wide use world-wide

return: array barcode representation.
param: $code (string) code to represent.
param: $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)

get128ABsequence($code)   X-Ref
Split text code in A/B sequence for 128 code

return: array sequence
param: $code (string) code to split.

barcode_eanupc($code, $len=13)   X-Ref
EAN13 and UPC-A barcodes.
EAN13: European Article Numbering international retail product code
UPC-A: Universal product code seen on almost all retail products in the USA and Canada
UPC-E: Short version of UPC symbol

return: array barcode representation.
param: $code (string) code to represent.
param: $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A

barcode_eanext($code, $len=5)   X-Ref
UPC-Based Extensions
2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
5-Digit Ext.: Used to mark suggested retail price of books

return: array barcode representation.
param: $code (string) code to represent.
param: $len (string) barcode type: 2 = 2-Digit, 5 = 5-Digit

barcode_postnet($code, $planet=false)   X-Ref
POSTNET and PLANET barcodes.
Used by U.S. Postal Service for automated mail sorting

return: array barcode representation.
param: $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or DDDDD-DDDD.
param: $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET

barcode_rms4cc($code, $kix=false)   X-Ref
RMS4CC - CBC - KIX
RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.

return: array barcode representation.
param: $code (string) code to print
param: $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum) - in this case the house number must be sufficed with an X and placed at the end of the code.

barcode_codabar($code)   X-Ref
CODABAR barcodes.
Older code often used in library systems, sometimes in blood banks

return: array barcode representation.
param: $code (string) code to represent.

barcode_code11($code)   X-Ref
CODE11 barcodes.
Used primarily for labeling telecommunications equipment

return: array barcode representation.
param: $code (string) code to represent.

barcode_pharmacode($code)   X-Ref
Pharmacode
Contains digits (0 to 9)

return: array barcode representation.
param: $code (string) code to represent.

barcode_pharmacode2t($code)   X-Ref
Pharmacode two-track
Contains digits (0 to 9)

return: array barcode representation.
param: $code (string) code to represent.

barcode_imb($code)   X-Ref
IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
(requires PHP bcmath extension)
Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and 90–94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999,  000000000–999999999, and 00000000000–99999999999.</li></ul>

return: array barcode representation.
param: $code (string) code to print, separate the ZIP (routing code) from the rest using a minus char '-' (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode)

barcode_imb_pre($code)   X-Ref
IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200

return: array barcode representation.
param: $code (string) pre-formatted IMB barcode (65 chars "FADT")

dec_to_hex($number)   X-Ref
Convert large integer number to hexadecimal representation.
(requires PHP bcmath extension)

return: string hexadecimal representation
param: $number (string) number to convert specified as a string

hex_to_dec($hex)   X-Ref
Convert large hexadecimal number to decimal representation (string).
(requires PHP bcmath extension)

return: string hexadecimal representation
param: $hex (string) hexadecimal number to convert specified as a string

imb_crc11fcs($code_arr)   X-Ref
Intelligent Mail Barcode calculation of Frame Check Sequence

return: int 11 bit Frame Check Sequence as integer (decimal base)
param: $code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified).

imb_reverse_us($num)   X-Ref
Reverse unsigned short value

return: int reversed value
param: $num (int) value to reversr

imb_tables($n, $size)   X-Ref
generate Nof13 tables used for Intelligent Mail Barcode

return: array requested table
param: $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
param: $size (int) size of table (78 for n=2 and 1287 for n=5)