Our Customers
Contact Us Email: support@barcodelib.com
Home > Java Barcode Generator > Java Barcode Generation Guide > Java EAN-13 Barcode Generator
Download Barcode for Java Trial

Java EAN-13 Barcodes Generator Guide

EAN-13 Bar Code Generation Guide in Java class, J2EE, Jasper Reports, iReport & Eclipse BIRT
  • Comprehensive barcoding toolkit for Java with advanced EAN-13 generation functions
  • 100% build in Java, compatible with JDK 1.4 and later version
  • Easily generate EAN-13 barcodes in Java applications with virtual machine
  • Generate high-readability EAN-13 barcodes in JPEG, GIF & PNG image formats
  • Generate EAN-13 barcode in Jasper Reports & iReport
  • Generate EAN-13 barcode in Eclipse BIRT
  • Professional Java Barcode Generator library since 2003
  • Four types of royalty-free developer license with lifelong to use
EAN-13 Barcode Introduction
EAN-13 is also known as European Article Number 13, EAN-13 Supplement 5/Five-digit Add-On, EAN-13 Supplement 2/Two-digit Add-On, EAN-13+5, EAN-13+2, EAN13, EAN13+5, EAN13+2, UPC-13, GTIN-13, GS1-13, EAN/UCC-13.
A European Article Number (EAN) is a barcoding standard which is a superset of the original 12-digit Universal Product Code (UPC) system developed in North America. The EAN-13 barcode is defined by the standards organisation GS1. It is also called a Japanese Article Number (JAN) in Japan. UPC, EAN, and JAN numbers are collectively called Global Trade Item Numbers (GTIN), though they can be expressed in different types of barcodes.
The EAN-13 barcodes are used worldwide for marking retail goods. The less commonly used EAN-8 barcodes are used also for marking retail goods; however, they are usually reserved for smaller items, for example confectionery.

Sample of an EAN-13 Barcode
The value to encode by EAN-13 has the following structure:
  • 2 or 3 digits for Number System or Country Code
  • 5 or 4 digits for Manufacturer (Company) Code or prefix
  • 5 digits for Product Code
  • 1 digit for checksum
Each country has a numbering authority which assigns manufacturer codes to companies within its jurisdiction.
Add-On or Supplement code
The Add-On Symbols were designed to encode information supplementary to that in the main bar code symbol on periodicals and paperback books. The Add-On can be composed of 2 or 5 digits only.

Sample of an EAN-13 Five-Digit Add-On Barcode

Sample of an EAN-13 Five-Digit Add-On Barcode
EAN-13 Encoding Data Scope
EAN13 Barcode for Java supports:
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
How to Generate EAN-13 Barcode in Java Class?
The following Java code illustrates how to create a EAN-13 barcode, and output to various formats.
1     Linear linear = new Linear(); 
2 linear.setType(Linear.EAN13);
3 linear.setData("123456789012");
4 linear.renderBarcode("c:/barcode.gif");

5 BufferedImage bufferedImage = linear.renderBarcode();

6 byte[] barcodeBytes = linear.renderBarcodeToBytes();

7 Graphics2D g = ...
8 Rectangle2D rectangle = ...
9 linear.renderBarcode(g, rectangle);

10 OutputStream outputStream = ...
11 linear.renderBarcode(outputStream);
  • Create a Linear barcode object (line 1)
  • Set Linear object barcode type to EAN-13 (line 2)
  • Set EAN-13 barcode data to encode (line 3)
  • Encode generated EAN-13 barcode into gif image file (line 4)
  • Generate EAN-13 and output to BufferedImage object (line 5)
  • Generate EAN-13 in bitmap and output to byte[] (line 6)
  • Generate EAN-13 and draw to defined area (Rectangle2D) on Graphics2D (line 7-9)
  • Generate EAN-13 and output to OutputStream (line 10-11)
How to Generate EAN-13 Barcode Image in Java Web Applications?
There are two methods to create EAN-13 barcode images in your Java web applications.
  1. The simplest way is to stream barcode image using our buildin barcode servlet application.
    • Download the Barcode for Java Trial Package, and unzip it.
    • Under java_barcode_trial package, copy barcode folder to your java servlet container like tomcat.
    • Restart tomcat. Now you have installed successfully.
    • To test your installation, open your web browser and navigate to:
    • To create barcode image in your JSP or html page, you need pass the url to IMG tag src value. For example,
      <img src="http://YourDomain:Port/barcode/linear?Data=123456789012&Type=EAN13" />
      Using this method, it will not generate any barcode images in your server side.
  2. The second method is to generate barcode images in your server side.
    • Create a barcode image in server side, like
      Linear linear = new Linear();
      linear.renderBarcode("C:/Tools/Tomcat 5.5/webapps/YourWebApp/barcode-images/barcode.gif");
    • In your JSP or HTML page, you need use IMG tag to display generated image, like
      <img src="http://YourDomain:Port/YourWebApp/barcode-images/barcode.gif" />
How to Generate Barcode EAN-13 Image in Jasper Reports, iReport, Eclipse BIRT?
Java EAN-13 Barcode Property Settings
  1. Set the type property to Linear.EAN13 or Linear.EAN13_2 or Linear.EAN13_5
    Servlet URL Parameter: "Type". Value: 10 (EAN13), 11 (EAN13 +2), 12 (EAN13 +5). Sample: &Type=10.
  2. Set the data property with the value to encode. Type is String.
    User should only provide 12 digits, and DO NOT include last digit checksum character.
    Servlet URL Parameter: Data.
    • Valid Data Scope:
      • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    • Valid Data Format:
      12 digits. There are totally 13 digits in EAN-13 barcode, first 12 digits are barcode value, and last digit is the checksum digit, which is generated by barcode library automatically.
    • Sample: "123456789012".
  3. Set the sData property with the supplement value to encode. Type is string.
    Provide 2 digits for barcode type EAN13_2, and provide 5 digits for type EAN13_5.
    Sample for Linear.EAN13_2: "12".
    Sample for Linear.EAN13_5: "12345".
    Servlet URL Parameter: SData.
  4. addCheckSum property is not applied here. Barcode Library will always add a check character in the last digit (modulo 10).
  5. Barcode image size settings.
    • Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin.
      Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2).
      Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0.
    • Set the X (for barcode module width) and Y (for barcode module height) properties.
      Both types are float. Default X is 3. Y is 75.
      Servlet URL Parameter: "X", "Y". Sample: &X=3&Y=75.
    • Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float.
      Default values are 0 for all 4 margin settings.
      Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0.
    • Set the resolution property (Value is expressed in DPI - Dots per inch).
      Default is 72 dpi.
      Servlet URL Parameter: "Resolution". Sample: &Resolution=72.
  6. Setting up text style in barcode image.
    • Set the showText properties. If this value is true, barcode data will be displayed with the barcode.
      Default is true.
      Servlet URL Parameter: "ShowText". Value: "t" (true), "f" (false). Sample: &ShowText=t.
    • Set the textFont property. The font used to display text in barcode image.
      Default is new Font("Arial", Font.PLAIN, 11).
      Servlet URL Parameter: "TextFont". Value format: [font name]|[font style]|[font size]. Sample Values: &TextFont=Arial|Bold|12
  7. With rotate property, you can display barcode horizontally or vertically.
    Default value is 0.
    Servlet URL Parameter: "Rotate". Sample: &Rotate=0.
    Value can be:
    • 0 (Linear.ANGLE_0),
    • 1 (Linear.ANGLE_90),
    • 2 (Linear.ANGLE_180),
    • 3 (Linear.ANGLE_270).
How to Set Generated EAN-13 Barcode Image Size?

All Java Barcode Types/Symbologies

Encode Linear Barcodes:
Encode Matrix Barcodes: