Manual - GS1-128 (EAN-128)

Introduction

The GS1-128 code is a normalization of the standards from http://www.gs1.org/ based on the BCGcode128. This code is an international standard which provides a way to exchange data between producers and distributors. The GS1-128 must start with the function 1 (~F1). It can contain multiple identifiers, however it mustn't be larger than 48 characters, this limit excludes the mandatory character ~F1. In order to facilitate the reading, the identifiers are surrounded by parentheses in the label; those parentheses are not encoded in the barcode.

Since the GS1 identifiers change often, we have separated the code in a separate package. To work properly, you should install the package barcode-bakery/gs1ai.

There are different ways to send the data of your barcode to the method parse(), for instance, the following code:

IdentifierContent
0112345678912343
92123
15880422

(01)12345678912343(92)123(15)880422

can be encoded like this

  • A formatted string:
    $code->parse('(01)12345678912343(92)123~F1(15)880422');
  • A non-formatted string:
    $code->parse('011234567891234392123~F115880422');
  • A simple formatted table:
    $code->parse(array('(01)12345678912343', '(92)123', '(15)880422'));
  • A simple mixed table:
    $code->parse(array('0112345678912343', '(92)123~F115880422'));
  • A double table containing couples (ID, CONTENT)
    $code->parse(array(
        array('01', '12345678912343'),
        array('92', '123'),
        array('15', '880422')
    ));

* Note about ~F1: If you provide the data in a string, you have to provide a separator at the end of your identifier if this one doesn't cover the maximum and is not positioned at the end of the code.

If you didn't indicate the checksum in the data and it is mandatory, it will be automatically calculated.
ex: $code->parse('011234567891234'); will give you: (01)1234567891234 3

There are two standards for the GS1-128, the strict and legacy modes. In legacy mode, separators are added between each identifier. In strict mode, separators are added only if the content of your data doesn't cover the maximum allowed. In this mode, it is highly recommended to use the table C if you use only numbers in your barcode. The following example will help you to understand the difference between those two modes:

Legacy Mode:
(01) content with fixed size [Separator] (91) content with variable size [Separator] (8020) content with variable size

Strict Mode:
(01) content with fixed size (91) content with variable sizes [Separator *] (8020) content with variable size

* The identifier 91 must contain between 1 and 90 characters. If this one contains 90 characters, there is no separator added.

Identifier list:

IdNameTypeSizeChecksum
00 Serial Shipping Container Code (SSCC-18) Numeric 2 + 18 Yes
01 Global Trade Item Number (GTIN) Numeric 2 + 14 Yes
02 GTIN of Contained Trade Items Numeric 2 + 14 Yes
10 Batch or Lot Number Alphanumeric 2 + 1 to 20 No
11 Production Date Date 2 + 6 No
12 Due Date Date 2 + 6 No
13 Packaging Date Date 2 + 6 No
15 Best Before Date Date 2 + 6 No
16 Sell By Date Date 2 + 6 No
17 Expiration Date Date 2 + 6 No
20 Internal Product Variant Numeric 2 + 2 No
21 Serial Number Alphanumeric 2 + 1 to 20 No
22 Consumer Product Variant Alphanumeric 2 + 1 to 20 No
235 Third Party Controlled, Serialised Extension of GTIN (TPX) Alphanumeric 3 + 1 to 28 No
240 Additional Item Identification Alphanumeric 3 + 1 to 30 No
241 Customer Part Number Alphanumeric 3 + 1 to 30 No
242 Made-to-Order Variation Number Alphanumeric 3 + 1 to 6 No
243 Packaging Comnponent Number Alphanumeric 3 + 1 to 20 No
250 Second Serial Number Alphanumeric 3 + 1 to 30 No
251 Reference to Source Entity Alphanumeric 3 + 1 to 30 No
253 Global Document Type Identifier (GDTI) Numeric 3 + 14 to 30 No
254 GLN Extension Component Numeric 3 + 1 to 20 No
255 Global Coupon Number (GCN) Numeric 3 + 14 to 25 No
30 Variable Count of Items (variable measure trade item) Numeric 2 + 1 to 8 No
310y Net Weight in kilograms (variable measure trade item) Numeric 4 + 6 No
311y Length or 1st Dimension, in meters (variable measure trade item) Numeric 4 + 6 No
312y Width, Diameter, or 2nd Dimension, in meters (variable measure trade item) Numeric 4 + 6 No
313y Depth, Thickness, Height, or 3rd Dimension, in meters (variable measure trade item) Numeric 4 + 6 No
314y Area, in square meters (variable measure trade item) Numeric 4 + 6 No
315y Net Volume, in liters (variable measure trade item) Numeric 4 + 6 No
316y Net Volume, in cubic meters (variable measure trade item) Numeric 4 + 6 No
320y Net Weight, in pounds (variable measure trade item) Numeric 4 + 6 No
321y Length or 1st Dimension, in inches (variable measure trade item) Numeric 4 + 6 No
322y Length or 1st Dimension, in feet (variable measure trade item) Numeric 4 + 6 No
323y Length, 1st Dimension, in yards (variable measure trade item) Numeric 4 + 6 No
324y Width, Diameter, or 2nd Dimension, in inches (variable measure trade item) Numeric 4 + 6 No
325y Width, Diameter, or 2nd Dimension, in feet (variable measure trade item) Numeric 4 + 6 No
326y Width, Diameter, or 2nd Dimension, in yards (variable measure trade item) Numeric 4 + 6 No
327y Depth, Thickness, Height, or 3rd Dimension, in inches (variable measure trade item) Numeric 4 + 6 No
328y Depth, Thickness, Height, or 3rd Dimension, in feet (variable measure trade item) Numeric 4 + 6 No
329y Depth, Thickness, Height, or 3rd Dimension, in yards (variable measure trade item) Numeric 4 + 6 No
330y Logistic Weight, in kilograms Numeric 4 + 6 No
331y Length, or 1st Dimension, in meters Numeric 4 + 6 No
332y Width, Diameter, or 2nd Dimension, in meters Numeric 4 + 6 No
333y Depth, Thickness, Height, or 3rd Dimension, in meters Numeric 4 + 6 No
334y Area, in square meters Numeric 4 + 6 No
335y Logistic Volume, in liters Numeric 4 + 6 No
336y Logistic Volume, in cubic meters Numeric 4 + 6 No
337y Kilograms per square meter Numeric 4 + 6 No
340y Logistic Weight, in pounds Numeric 4 + 6 No
341y Length or 1st Dimension, in inches Numeric 4 + 6 No
342y Length or 1st Dimension, in feet Numeric 4 + 6 No
343y Container Length/1st Dimension in, in yards Numeric 4 + 6 No
344y Width, Diameter, or 2nd Dimension, in inches Numeric 4 + 6 No
345y Width, Diameter, or 2nd Dimension, in feet Numeric 4 + 6 No
346y Width, Diameter, or 2nd Dimension, in yards Numeric 4 + 6 No
347y Depth, Thickness, Height, or 3rd Dimension, in inches Numeric 4 + 6 No
348y Depth, Thickness, Height, or 3rd Dimension, in feet Numeric 4 + 6 No
349y Depth, Thickness, Height, 3rd Dimension, in yards Numeric 4 + 6 No
350y Area, in square inches (variable measure trade item) Numeric 4 + 6 No
351y Area, in square feet (variable measure trade item) Numeric 4 + 6 No
352y Area, in square yards (variable measure trade item) Numeric 4 + 6 No
353y Area, in square inches Numeric 4 + 6 No
354y Area, in square feet Numeric 4 + 6 No
355y Area, in square yards Numeric 4 + 6 No
356y Net Weight, in troy ounces (variable measure trade item) Numeric 4 + 6 No
357y Net Weight or volume, in ounces (variable measure trade item) Numeric 4 + 6 No
360y Net Volume, in quarts (variable measure trade item) Numeric 4 + 6 No
361y Net Volume, in U.S. gallons (variable measure trade item) Numeric 4 + 6 No
362y Logistic Volume, in quarts Numeric 4 + 6 No
363y Logistic Volume, in U.S. gallons Numeric 4 + 6 No
364y Net Volume, in cubic inches (variable measure trade item) Numeric 4 + 6 No
365y Net Volume, in cubic feet (variable measure trade item) Numeric 4 + 6 No
366y Net Volume, in cubic yards (variable measure trade item) Numeric 4 + 6 No
367y Logistic Volume, in cubic inches Numeric 4 + 6 No
368y Logistic Volume, in cubic feet Numeric 4 + 6 No
369y Logistic Volume, in cubic yards Numeric 4 + 6 No
37 Count of trade items Numeric 2 + 1 to 8 No
390y Applicable Amount Payable or Coupon Value, in local currency Numeric 4 + 1 to 15 No
391y Applicable Amount Payable with ISO Currency Code Numeric 4 + 4 to 18 No
392y Applicable Amount Payable, Single Monetary Area (variable measure trade item) Numeric 4 + 1 to 15 No
393y Applicable Amount Payable With ISO Currency Code (variable measure trade item) Numeric 4 + 4 to 18 No
394y Percentage Discount of a Coupon Numeric 4 + 4 No
395y Amount Payable per unit of measure single monetary area (variable measure trade item) Numeric 4 + 6 No
400 Customer's Purchase Order Number Alphanumeric 3 + 1 to 30 No
401 Global Identification Number for Consignment (GINC) Alphanumeric 3 + 1 to 30 No
402 Global Shipment Identification Number (GSIN) Numeric 3 + 17 No
403 Routing Code Alphanumeric 3 + 1 to 30 No
410 Ship To/Deliver To Global Location Number Numeric 3 + 13 Yes
411 Bill To/Invoice To Global Location Number Numeric 3 + 13 Yes
412 Purchased From Global Location Number Numeric 3 + 13 Yes
413 Ship For/Deliver For/Forward To Global Location Number Numeric 3 + 13 Yes
414 Identification of a Physical Location - Global Location Number Numeric 3 + 13 Yes
415 Global Location Number of The Invoicing Party Numeric 3 + 13 Yes
416 Global Location Number of The Production or Service Location Numeric 3 + 13 Yes
417 Party GLN Numeric 3 + 13 Yes
420 Ship To/Deliver To Postal Code Within a Single Postal Authority Alphanumeric 3 + 1 to 20 No
421 Ship To/Deliver To Postal Code With ISO Country Code Alphanumeric 3 + 4 to 12 No
422 Country of Origin of a Trade Item Numeric 3 + 3 No
423 Country of Initial Processing Numeric 3 + 3 to 15 No
424 Country of Processing Numeric 3 + 3 No
425 Country of Disassembly Numeric 3 + 3 No
426 Country Covering Full Process Chain Numeric 3 + 3 No
4300 Ship-to / Deliver-to company name Alphanumeric 4 + 1 to 35 No
4301 Ship-to / Deliver-to contact Alphanumeric 4 + 1 to 35 No
4302 Ship-to / Deliver-to address line 1 Alphanumeric 4 + 1 to 70 No
4303 Ship-to / Deliver-to address line 2 Alphanumeric 4 + 1 to 70 No
4304 Ship-to / Deliver-to suburb Alphanumeric 4 + 1 to 70 No
4305 Ship-to / Deliver-to locality Alphanumeric 4 + 1 to 70 No
4306 Ship-to / Deliver-to region Alphanumeric 4 + 1 to 70 No
4307 Ship-to / Deliver-to country code Alphanumeric 4 + 2 No
4308 Ship-to / Deliver-to telephone number Alphanumeric 4 + 1 to 30 No
4310 Return-to company name Alphanumeric 4 + 1 to 35 No
4311 Return-to contact Alphanumeric 4 + 1 to 35 No
4312 Return-to address line 1 Alphanumeric 4 + 1 to 70 No
4313 Return-to address line 2 Alphanumeric 4 + 1 to 70 No
4314 Return-to suburb Alphanumeric 4 + 1 to 70 No
4315 Return-to locality Alphanumeric 4 + 1 to 70 No
4316 Return-to region Alphanumeric 4 + 1 to 70 No
4317 Return-to country code Alphanumeric 4 + 2 No
4318 Return-to postal code Alphanumeric 4 + 1 to 20 No
4319 Return-to telephone number Alphanumeric 4 + 1 to 30 No
4320 Service code description Alphanumeric 4 + 1 to 35 No
4321 Dangerous goods flag Numeric 4 + 1 No
4322 Authority to leave Numeric 4 + 1 No
4323 Signature required flag Numeric 4 + 1 No
4324 Not before delivery date time DateTime 4 + 10 No
4325 Not after delivery date time DateTime 4 + 10 No
4326 Release date Date 4 + 6 No
427 Country Subdivision of Origin Alphanumeric 3 + 1 to 3 No
7001 NATO Stock Number (NSN) Numeric 4 + 13 No
7002 UN/ECE Meat Carcasses and Cuts Classification Alphanumeric 4 + 1 to 30 No
7003 Expiration Date and Time DateTime 4 + 10 No
7004 Active Potency Numeric 4 + 1 to 4 No
7005 Catch Area Alphanumeric 4 + 1 to 12 No
7006 First Freeze Date Numeric 4 + 6 No
7007 Harvest Date Numeric 4 + 6 to 12 No
7008 Species For Fishery Purposes Alphanumeric 4 + 1 to 3 No
7009 Fishing Gear Type Alphanumeric 4 + 1 to 10 No
7010 Production Method Alphanumeric 4 + 1 to 2 No
7020 Refurbishment Lot ID Alphanumeric 4 + 1 to 20 No
7021 Functional Status Alphanumeric 4 + 1 to 20 No
7022 Revision Status Alphanumeric 4 + 1 to 20 No
7023 Global Individual Asset Identifier (GIAI) of an Assembly Alphanumeric 4 + 1 to 30 No
703s Number of Processor with ISO Country Code Alphanumeric 4 + 3 to 30 No
7040 GS1 UIC with Extension 1 and Importer index Alphanumeric 4 + 4 No
710 National Healthcare Reimbursement Number (NHRN) - Germany PZN Alphanumeric 3 + 1 to 20 No
711 National Healthcare Reimbursement Number (NHRN) - France CIP Alphanumeric 3 + 1 to 20 No
712 National Healthcare Reimbursement Number (NHRN) - Spain CN Alphanumeric 3 + 1 to 20 No
713 National Healthcare Reimbursement Number (NHRN) - Brasil DRN Alphanumeric 3 + 1 to 20 No
714 National Healthcare Reimbursement Number (NHRN) - Portugal AIM Alphanumeric 3 + 1 to 20 No
723y Certification reference Alphanumeric 4 + 2 to 30 No
7240 Protocol ID Alphanumeric 4 + 1 to 20 No
8001 Roll Products - Width/Length/Core Diameter/Direction/Splices Numeric 4 + 14 No
8002 Cellular Mobile Telphone Identifier Alphanumeric 4 + 1 to 20 No
8003 Global Returnable Asset Identifier (GRAI) Alphanumeric 4 + 15 to 30 No
8004 Global Individual Asset Identifier (GIAI) Alphanumeric 4 + 1 to 30 No
8005 Price per Unit of Measure Numeric 4 + 6 No
8006 Identification of an Individual Trade Item Piece Numeric 4 + 18 No
8007 International Bank Account Number (IBAN) Alphanumeric 4 + 1 to 34 No
8008 Date and Time of Production DateTime 4 + 8 to 12 No
8009 Optically Readable Sensor Indicator Alphanumeric 4 + 1 to 50 No
8010 Component/Part Identifier (CPID) Alphanumeric 4 + 1 to 30 No
8011 Component/Part Identifier Serial Number (CPID Serial) Numeric 4 + 1 to 12 No
8012 Software Version Alphanumeric 4 + 1 to 20 No
8013 Global Model Number (GMN) Numeric 4 + 1 to 30 No
8017 Global Service Relation Number to Identify the Relationship Between an Organisation Offering Services and the Provider of Services Numeric 4 + 18 No
8018 Global Service Relation Number to Identify the Relationship Between an Organisation Offering Services and the Recipient of Services Numeric 4 + 18 No
8019 Service Relation Instance Number (SRIN) Numeric 4 + 1 to 10 No
8020 Payment Slip Reference Number Alphanumeric 4 + 1 to 25 No
8026 Identification of pieces of a trade item (ITIP) contained in a logistic unit Numeric 4 + 18 No
8110 Coupon Code Identification for Use in North America Alphanumeric 4 + 1 to 70 No
8111 Loyalty Points of a Coupon Numeric 4 + 4 No
8112 Paperless Coupon Code Identification for Use in North America (AI 8112) Alphanumeric 4 + 1 to 70 No
8200 Extended Packaging URL Alphanumeric 4 + 1 to 70 No
90 Information Mutually Agreed Between Trading Partners Alphanumeric 2 + 1 to 30 No
91 Internal Company Codes Alphanumeric 2 + 1 to 90 No
92 Internal Company Codes Alphanumeric 2 + 1 to 90 No
93 Internal Company Codes Alphanumeric 2 + 1 to 90 No
94 Internal Company Codes Alphanumeric 2 + 1 to 90 No
95 Internal Company Codes Alphanumeric 2 + 1 to 90 No
96 Internal Company Codes Alphanumeric 2 + 1 to 90 No
97 Internal Company Codes Alphanumeric 2 + 1 to 90 No
98 Internal Company Codes Alphanumeric 2 + 1 to 90 No
99 Internal Company Codes Alphanumeric 2 + 1 to 90 No
* Date is in the "YYMMDD" format.
* Date is in the "YYMMDDHHMMSS" format. The seconds might not be supported by all AI.

This class inherits the BCGcode128 class.

Example

Methods

BCGgs1128's Methods

BCGBarcode1D's Methods

BCGBarcode's Methods

Code Example


<?php
use BarcodeBakery\Common\BCGFontFile;
use BarcodeBakery\Common\BCGColor;
use BarcodeBakery\Common\BCGDrawing;
use BarcodeBakery\Barcode\BCGgs1128;

$font = new BCGFontFile(__DIR__ . '/font/Arial.ttf', 18);
$colorBlack = new BCGColor(0, 0, 0);
$colorWhite = new BCGColor(255, 255, 255);

// Barcode Part
$code = new BCGgs1128();
$code->setScale(2);
$code->setThickness(30);
$code->setForegroundColor($colorBlack);
$code->setBackgroundColor($colorWhite);
$code->setFont($font);
$code->setStrictMode(true);
$code->setApplicationIdentifiers(BarcodeBakery\Common\GS1\GS1AI::getDefaultAIData());
$code->parse('011234567891234392123~F115880422');

// Drawing Part
$drawing = new BCGDrawing($code, $colorWhite);

header('Content-Type: image/png');

$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>

Method explanations

  • __construct($start) — Specifies by which table the barcode should start
    Description
    The argument can be A, B, C or null. See the setStart() method for more information.
    The default value is C.
  • getStrictMode() — Gets if the strict mode is activated
    Description
    See setStrictMode() for more details.
    Returns
    bool - true if activated, false otherwise
  • setStrictMode($mode) — Specifies which mode to use to generate the barcode
    Description
    By setting the argument to true, the strict mode is used (which is the default mode), if you set false, the code will be generated following the legacy mode. For more information about those two modes, see the introduction.
  • getAllowsUnknownIdentifier() — Gets if unknown identifiers are allowed
    Description
    See setAllowsUnknownIdentifier() for more details.
    Returns
    bool - true if activated, false otherwise
  • setAllowsUnknownIdentifier($allow) — Specifies if unknown identifiers are allowed
    Description
    By setting to true, you are allowed to use any kind of identifiers.
    In this case, a ~F1 character will be added at the end of each identifier even if it wouldn't be necessary.
    The default value is false.
  • getNoLengthLimit() — Gets if no limit is enforced
    Description
    See setNoLengthLimit() for more details.
    Returns
    bool - true if activated, false otherwise
  • setNoLengthLimit($noLengthLimit) — Specifies if no length limit is enforced
    Description
    By setting true, you can use an unlimited amount of identifiers.
    Otherwise, GS1 recommends not using more than 48 characters.
    The default value is false.
  • getApplicationIdentifiers() — Gets the AI table
    Description
    Gets the AI table that has been previously set.
  • setApplicationIdentifiers($aiDatas) — Specifies which AI can be used
    Description
    Attaches the table of authorized AI to the barcode so the parsing can happen correctly. Check the introduction to understand how to load the default AI.
  • getThickness() — Returns the thickness of the barcode
    Description
    The thickness of the barcode in pixels. The value isn't multiplied by the scale.
    Returns
    int - value in pixels
  • setThickness($thickness) — Specifies the thickness of the barcode
    Description
    The thickness of the barcode in pixels. This is the vertical size.
  • getLabel() — Gets the label
    Description
    Returns the real value that will be displayed with the barcode. You have to have called the parse() method first.
    Returns
    string - final label
  • setLabel($label) — Sets the label
    Description
    The text label will be written below or above the barcode depending on the barcode. You can write the special value BCGBarcode1D::AUTO_LABEL if you would like your text to be chosen automatically. It will be the value passed to the parse() method.
  • getFont() — Gets the text font for the label
    Description
    Gets the text font for the label.
    Returns
  • setFont($font) — Sets the text font for the label
    Description
    The value of the argument can be either an instance of the BCGFontFile class, BCGFontPhp, or a number between 1 and 5.
    If you are using numbers 1 through 5, PHP fonts are used. Check the PHP Manual.
  • getChecksum() — Gets the checksum appended to the barcode
    Description
    Returns the value that will be appended to the barcode. This method must be called after the method parse().
    Returns
    int - checksum added or false if no checkum is included
  • setDisplayChecksum($display) — Specifies the checksum to be added to the label
    Description
    Setting true will append the checksum to the default label.
    The default value is true.
  • parse($text) — Analyzes a $text message to draw afterwards
    Description
    The data you pass to the $text argument must be supported by the type of barcode you use.
    Check each barcode's introduction section to obtain more information on how to use this method within each symbology.
  • draw($image) — Draws the barcode on the $image
    Description
    The value of the $image argument must be an image resource. The size of the image can be defined by the value received from getDimension().
  • getDimension($width, $height) — Returns an array containing the required size for the image
    Description
    Returns an array in which the first index is the image width and the second index is the image height.
    The arguments are used to specify the starting point of the drawing. Should be 0 for both.
    The BCGDrawing class uses this method to create the image resource.
    Returns
    array(int, int) - [0] is the width, [1] is the height
  • getScale() — Gets the scale of the barcode
    Description
    Gets the scale of the barcode. The value is the number of the "smallest" unit in pixel.
    Returns
    int - value in pixels
  • setScale($scale) — Sets the scale of the barcode
    Description
    The barcode will be $x times bigger. Then a pixel will be $x by $x for its size.
  • getForegroundColor() — Gets the color of the bars
    Description
    Gets the color of the bars of the barcode.
    Returns
  • setForegroundColor($color) — Sets the color of the bars
    Description
    Sets the color of the bars of the barcode. By default, the color is black. This argument can be a BCGColor class or any other argument that BCGColor can accept in its constructor.
  • getBackgroundColor() — Gets the color of the spaces
    Description
    Gets the color of the spaces of the barcode.
    Returns
  • setBackgroundColor($color) — Sets the color of the spaces
    Description
    Sets the color of the spaces of the barcode. By default, the color is white. This argument can be a BCGColor class or any other argument that BCGColor can accept in its constructor.
  • setColor($foregroundColor, $backgroundColor) — Sets the color of the bars and spaces
    Description
    An easy and fast method to set the color of the bars and spaces. Check the setForegroundColor() and setBackgroundColor().
  • getOffsetX() — Gets the X offset
    Description
    Gets the X offset of the barcode in pixels. The value isn't multiplied by the scale.
    Returns
    int - value in pixels
  • setOffsetX($value) — Sets the X offset
    Description
    Specifies the X offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
  • getOffsetY() — Gets the Y offset
    Description
    Gets the Y offset of the barcode in pixels. The value isn't multiplied by the scale.
    Returns
    int - value in pixels
  • setOffsetY($value) — Sets the Y offset
    Description
    Specifies the Y offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
  • addLabel($label) — Adds a label to the graphic
    Description
    Adds a BCGLabel object to the drawing.
  • removeLabel($label) — Removes a label from the graphic
    Description
    Removes a specific BCGLabel object from the drawing.
  • clearLabels() — Removes the labels from the graphic
    Description
    Clears the BCGLabel objects from the drawing.