Home  >  Barcode Libraries  >  Java Barcode  >  Java Barcode Generation Guide  >  Java Barcode EAN 8 Generator for Java Class

Java EAN-8 Generator


Barcode EAN-8 Generation in Java Class, Jasper Reports, iReport, BIRT

Java Barcode offers the most affordable Java barcode generator for barcode Java professionals.


Java EAN-8 Introduction


EAN-8 is also known as European Article Number 8, EAN-8 Supplement 5/Five-digit Add-On, EAN-8 Supplement 2/Two-digit Add-On, EAN-8+5, EAN-8+2, EAN8, EAN8+5, EAN13+2, UPC-8, GTIN-8, GS1-8, EAN/UCC-8

An EAN-8 is a barcode and is derived from the longer European Article Number (EAN-13) code. It was introduced mainly to use on small packages where an EAN-13 barcode would be impractical; for example on cigarettes, pencils even though not used very common and chewing gum packets.


Java EAN-8 Properties


EAN-8 Type Value: com.keepdynamic.barcode.generator.Linear.EAN8 (13).

EAN-8 Supplement 2 Type Value: com.keepdynamic.barcode.generator.Linear.EAN8_2 (14).

EAN-8 Supplement 5 Type Value: com.keepdynamic.barcode.generator.Linear.EAN8_5 (15).

Class Properties HTTP Parameters Default Comments
type type Linear.CODE128 (8) Barcode type
data data "" Barcode value to encode
supData sup-data "" Barcode supplementary value to encode. only valid for EAN-8, EAN-13, UPC-A, UPC-E, ISBN, ISSN
applyChecksum apply-checksum true Checksum for barcode value
uom uom BaseBarcode.PIXEL (0) Unit of meature for all size related settings. 0: pixel; 1: cm; 2: inch. Default is pixel
X x 2 Width of barcode module (narrow bar), default is 2 pixel
Y y 75 Barcode module height, default is 75 pixel
leftMargin left-margin 0 Barcode image left margin
rightMargin right-margin 0 Barcode image right margin
topMargin top-margin 0 Barcode image top margin
bottomMargin bottom-margin 0 Barcode image bottom margin
resolution resolution 72 Barcode image resolution in dpi
rotate rotate 0 Barcode rotate angle, valid values: 0, 90, 180, 270
displayText display-text true If true, display barcode value text, otherwise do not display.
textFont text-font "Arial", Font.PLAIN, 11 Barcode text font style
displayStartStopChar display-start-stop-char true For Code 39 Only. If true, display the start and stop char (*) in the begining and end of barcode value.
I i 1.0 For Code 39 Only. Width of intercharacter gap, This a multiple of X; default is 1.0
N n 2.0 For Code 39 and ITF14 Only. Wide vs narrow bar width ratio, valid range 2.0 - 3.0 inclusive, default is 2.0
bearerBarHori bearer-bar-hori 1.0 For ITF14 Only. The value of the horizontal bearer bar. Valid values are 0-10 which are a multiple of X.
bearerBarVert bearer-bar-vert 1.0 For ITF14 Only. The value of the vertical bearer bar. Valid values are 0-10 which are a multiple of X.
processTilde process-tilde false Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is false.
~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.
eci eci 3
fnc1Mode fnc1-mode 0 (none)
applicationIndicator ai 0



Java Barcode EAN-8 Generator - Java Class Implementation

The following Java code illustrates how to generate a barcode in Java class:



22       private static void testLinear() throws Exception 
23       { 
24           Linear barcode = new Linear(); 
25    
26           // set barcode properties 
27           barcode.setType(Linear.CODE128); 
28           barcode.setData("1234567890"); 
29    
30           // draw and generate barcode to specified file 
31           barcode.draw("C:\\Code128.gif"); 
32       } 


Java Barcode EAN-8 Generator - Java Servlet Implementation

The following Java code illustrates how to generate a barcode in Java Servlet class:

11   public class BarcodeServlet extends HttpServlet { 
12       public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException 
13       { 
14           try { 
15               Linear barcode = new Linear(); 
16    
17               // set barcode properties 
18               barcode.setType(Linear.CODE128); 
19               barcode.setData("1234567890"); 
20    
21               // draw and generate barcode to response's ServletOutputStream 
22               ServletOutputStream servletoutputstream = response.getOutputStream(); 
23    
24               barcode.draw(servletoutputstream); 
25    
26           } catch (Exception e) { 
27               throw new ServletException(e); 
28           } 
29       } 
30   } 
31   


View BarcodeServlet.java source code


Java Barcode EAN-8 Generator - HTTP Request Implementation

  1. Install Java Barcode Generator Servlet application to Tomcat or JBoss, developers need copy the barcode folder to your Tomcat application folder, and restart the Tomcat.

  2. After Tomcat restarted, open your browser and navigate to http://your_tomcat_url:port/barcode/linear?data=12345678&type=8

  3. You can also insert barcodes in HTML or JSP pages.

    <img src="http://your_tomcat_url:port/barcode/linear?data=12345678&type=8">


Java Barcode EAN-8 Generator - java.awt.Image Object Implementation

The following Java source code shows how to generate a barcode in a java.awt.Image object:


21    
22       private static void testLinear() throws Exception 
23       { 
24           Linear barcode = new Linear(); 
25            
26           // set barcode properties 
27           barcode.setType(Linear.CODE128); 
28           barcode.setData("1234567890"); 
29            
30           // create image object 
31           java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(300,300,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED ); 
32           // get graphic context of image 
33           java.awt.Graphics2D imgGraphics = image.createGraphics(); 
34    
35           // draw barcode to specified location in Rectangle 
36           barcode.draw(imgGraphics, new java.awt.Rectangle(0, 0, 300, 300)); 
37       } 






Java Barcode supports:

2D / Matrix Barcode Symbologies:

           Data Matrix, PDF-417, QR-Code

1D / Linear Barcode Symbologies:

           Codabar, Code 11, Code 2 of 5, Interleaved 2 of 5, Code 39,

           Code 93, Code 128 EAN 128, EAN 8, EAN 13,

           UPC-A, UPC-E, ISBN, ISSN, ITF-14,

           Identcode, Leitcode, MSI Plessey, Onecode, Planet,

           Postnet, RM4SCC,