barcodelib.com Home
  Contact Us  |   Purchase  
Google
BarcodeLib.com Home > Products > Barcode for Java > Barcode Ean 13


EAN-13 Barcode for Java, J2EE, JasperReports

It 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

Quick Navigate
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
EAN13 Barcode for Java supports:
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

The following code illustrates how to create a barcode in a Java class

1            Barcode barcode = new Barcode(); 
2            barcode.setData("123456789"); 
3            barcode.setType(Barcode.CODE39); 
4            barcode.createBarcodeImage("c:/code39.gif"); 


  • Create a Barcode object (line 1)
  • set Barcode object properties (line 2 - 3)
  • save into gif file (line 4)

There are two ways to create barcode images in your Java web applications.

  1. This is the simplest way to stream barcode image using our provided barcode servlet classes.

    And it will not save barcode images in your server side.

    • Under demo package, copy barcode folder to your java servlet container like tomcat.

    • To test your installation, goto http://YourDomain:Port/barcode/barcode?Data=123456789&Type=CODE39

    • To create barcode image in your JSP page, you can pass the url to IMG tag src value. For example, <img src="http://YourDomain:Port/barcode/barcode?Data=123456789&Type=CODE39" />

  2. The second method is similar with the way to generate barcode in Java applications.

    • Create a barcode image in server side

      1            Barcode barcode = new Barcode(); 
      2            barcode.setData("123456789"); 
      3            barcode.setType(Barcode.CODE39); 
      4            barcode.createBarcodeImage("C:/Tools/Tomcat 5.5/webapps/YourWebApp/bimages/code39.gif"); 
      
      
      

    • In your JSP page, you can using IMG tag to display generated image, like <img src="http://YourDomain:Port/YourWebApp/bimages/code39.gif" />

The following jasper xml content illustrates how to insert a barcode into JasperReports

<import value="com.barcodelib.barcode.BarcodeFactory"/> 

Import class BarcodeFactory to report.

<image scaleImage="Clip" hAlign="Center"> 
    <reportElement x="50" y="110" width="515" height="120"/> 
    <graphicElement/> 
    <imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[new com.barcodelib.barcode.BarcodeJasperRenderer(BarcodeFactory.createLinear(13, "0470821632"))]]></imageExpression> </image>

Please go to class BarcodeFactory in Java doc for all methods to create linear barcode.

Developers also can extend BarcodeFactory class to meet their own requirements. Complete BarcodeFactory.java Source Code

Just call Barcode object method createBarcodeImage, e.g. barcode.createBarcodeImage("c:/code39.gif");
Category Attribute/Method Servlet Attribute Default Value Description
Basic Settings
type Type CODE128
(22)
View all supported barcode types and values. Use the number value for the java bean class and the number or text value for the servlet. For example, the servlet query url should include: Type=CODE128 or Type=22
data Data "" This is the barcode text to be encoded. The type is String.
EAN 8: User should only provide 7 digits, and DO NOT include last digit checksum character.
EAN 13: User should only provide 12 digits, and DO NOT include last digit checksum character.
UPCA: User should only provide 11 digits, and DO NOT include last digit checksum character.
UPCE: User should only provide 6 digits, and DO NOT include last digit checksum character.
sData SData "" Supplement data for ISBN, ISSN, EAN 8, EAN 13, UPCA, UPCE only. The type is String.
addCheckSum AddCheckSum true Valid values are true and false. If barcode type check sum is compulsory or not applied, addCheckSum will not work. Please check each barcode symbologies to get more details.
processTilde ProcessTilde true For barcode Code 128 only. Set the ProcessTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is true. ~NNN: is used to represent the ASCII character with the value of NNN.
Codabar
codabarStartChar CodabarStartChar A One of four possible start characters (A, B, C, or D).
codabarStopChar CodabarStopChar A One of four possible stop characters (A, B, C, or D).
UPC-E
UPCENumberSystem UPCENumberSystem 0 Valid values are 0 and 1. The default is 0.
UPC-E may only be used if the number system is 0 or 1. The characters encoded are encoded with odd and even parity from the left-hand columns of the EAN-13 character formats in the table previously provided. The parity used for each character depends on the number system (0 or 1) and the check digit from the original UPC-A barcode.
Barcode Image Style
uom UOM 0 (pixel) Unit of measure for barcode size settings, type is float, default is 0 (pixel). Valid values are 0 (pixel), 1 (CM), 2 (Inch)
resolution Resolution 96 Image resolution. Default is 96 DPI.
barWidth BarWidth 0 Bar cell width, type is float. Its unit of measure is decided by uom.
leftMargin LeftMargin 0 The left margin. Its unit of measure is decided by uom.
rightMargin RightMargin 0 The right margin. Its unit of measure is decided by uom.
topMargin TopMargin 0 The top margin. Its unit of measure is decided by uom.
bottomMargin BottomMargin 0 The bottom margin. Its unit of measure is decided by uom.
showText ShowText true If this value is true (T in servlet), barcode data will be displayed with the barcode. The servlet convert "T" to true and "F" to false.
textFont TextFont Arial The font used to display text in barcode image. To change the font, use the following format:
  Font font = new Font("Arial", Font.BOLD, 13);
  barcode.setTextFont(font);
and to change the font in the servlet, use this format:
 &TextFont=Arial|Bold|13
imageFormat ImageFormat gif Valid values are "gif" and "jpeg". This setting is only valid in Servlet not in bean class.
rotate Rotate 0 If you want to rotate barcode image.
Value can be
0 (Image Bottom Facing Down),
1 (Image Bottom Facing Left),
2 (Image Bottom Facing Up),
3 (Image Bottom Facing Right)






   Copyright 2008 BarcodeLib.com. Provides High Quality Barcode Ean 13 for Java, Barcode Ean 13 for JasperReports Library. All rights reserved.