2D Barcode for Java
Linear Barcode for Java
Barcode Java > Generate Barcode Java

Java Barcode Generator is a Java Barcode Generation library which generates Linear (1D) and Matrix (2D) bar codes in Java applications.

Java Barcode Generator Library can be integrated into
  • Java Application (Java Class, Java Bean, Swing)
  • Java Web Application (JSP, Servlet, EJB, J2EE, Applet)
  • Java Reporting (Jasper Reports & iReport)
Java Barcode Generator - All Supporting Barcode Symbology Types
Select the following barcode types to know, how to generate specific barcode types in your Java project using Java Barcode Generator
Java Barcode Generator Developer Guide

1. Install & integrate Java Barcode Generator library (jar) into your Java project

  1. Download the trial version of Java Barcode Generator
  2. Unzip the package
  3. Add businessrefinery.barcode.jar to your Java project library or classpath

2. Generate & display barcode images in JSP or HTML pages using Java Barcode Generator Web Application

  1. In downloaded Java Barcode Generator package, copy folder barcoding to your Java Servlet Container's application folder.

    for example, in Tomcat, copy barcoding folder to {Tomcat Path}/webapps
  2. Restart Java Servlet Container (Tomcat)
  3. Insert the following html codes into your JSP or HTML pages, and it will generate barcode Code 128 with value 0123456789 in your web page.

    <img src="http://localhost:8080/barcoding/linear?DATA=0123456789&TYPE=11" border=0 />

3. Generate barcodes in Java Class

3 Steps to generate barcodes in Java class:

  1. Create a barcode object.

    To create Linear barcode (like Code39, Code128, GS1-128, UPC/EAN), use class com.businessrefinery.barcode.Barcode.

    To create Data Matrix barcode, use class com.businessrefinery.barcode.DataMatrix.

    To create PDF-417 barcode, use class com.businessrefinery.barcode.PDF417.

    To create QR-Code barcode, use class com.businessrefinery.barcode.QRCode.
  2. Set barcode properties.
  3. Draw barcode, and output to your required formats (image format like gif, jpeg, or Java Image object, or Java OutputStream object)

	// 1. Create linear barcode object.
        Barcode barcode = new Barcode();
        // 2. Set barcode properties.
        // 3. Draw barcode, and output to gif format

4. Generate barcodes in Java Servlet

Using Java Barcode Generator to generate barcodes in Servlet is an easy task.

Java Barcode Generator has provided you a method to draw barcodes and output to Java ServletOutputStream object.

        try {
            // Create barcode object and set barcode properties
            Barcode barcode = new Barcode();

            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            // Get Servlet OutputStream object
            ServletOutputStream servletoutputstream = response.getOutputStream();

            // Draw barcode and output to Servlet OutputStream object

        } catch (Exception e) {
            throw new ServletException(e);

5. Generate & Output barcode to different formats

Java Barcode Generator supports barcode generating into different formats.

  1. Draw barcode & encode to image file (GIF & JPEG)
  2. Generate barcode & output to java.awt.image.BufferedImage object
  3. Generate barcode & output to java.io.OutputStream object
  4. Generate barcode & output to byte array byte[] object
  5. Draw & paint barcode on java.awt.Graphics2D object
	// Create barcode object
        Barcode barcode = new Barcode();
        // Barcode property settings
        // Draw barcode & encode to image file (GIF & JPEG)
        // Generate barcode & output to java.awt.image.BufferedImage object
        BufferedImage bufImage = barcode.drawImage();
        // Generate barcode & output to java.io.OutputStream object
        barcode.drawOnStream("OutputStream object");
        // Generate barcode & output to byte array byte[] object
        byte[] barcodeBytes = barcode.drawImage2Bytes();
        // Draw & paint barcode on java.awt.Graphics2D object
        barcode.drawOnGraphics("[Graphics2D object], [Rectangle2D object]");

6. How to create barcodes in Jasper Reports?

View barcode generation in Jasper Reports using Java Barcode Generator

7. How to generate barcodes in iReport?

View barcode generation in iReport using Java Barcode Generator

Quick Links