Code 128 for Java
Barcode Java > Barcode in Java > Linear > Code 128

Code 128 is a very high-density barcode symbology. (A special version of it called GS1-128 is used extensively world wide in shipping and packaging industries.) It is used for alphanumeric or numeric-only barcodes. Code 128 is also called ANSI/AIM 128, ANSI/AIM Code 128, USS Code 128, Uniform Symbology Specification Code 128, Code 128 Code Set A, Code 128 Code Set B, Code 128 Code Set C, Code 128A, Code 128B, Code 128C.

Java Code-128 prints:
  • all 128 characters of ASCII
  • values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.

Java Code-128 Barcode Generator - Common Questions

1. How to generate Code-128 barcodes in JSP & HTML pages?

  1. Copy "barcoding" folder contents to your Java Servlet container like Tomcat or JBoss's applications folder
  2. Restart your Java Servlet container
  3. Open your web browser like IE, Firefox, and navigate to http://localhost:8080/barcoding/linear?DATA=0123456789&TYPE=11
  4. To generate Code128 barcode images in JSP or HTML pages, insert the following html img tag code:
    <img src="http://localhost:8080/barcoding/linear?DATA=0123456789&TYPE=11" border=0 />

2. How to create Code-128 barcodes in Java Servlet?

        try {
            Barcode barcode = new Barcode();

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


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

3. How to generate Code-128 barcodes in Java Class?

        Barcode barcode = new Barcode();

4. How to draw Code-128 barcodes to image files?

        Barcode barcode = new Barcode();

5. How to draw & print Code-128 barcodes to Java image objects or stream objects?

        Barcode barcode = new Barcode();
        barcode.drawOnGraphics("Graphics2D object");
        barcode.drawOnStream("OutputStream object");
Java Barcode Code-128 Generator - Barcode Property Settings

  • symbology : Barcode symbology type.

    Servlet Parameter: symbology; Default Value: Barcode.CODE128 (11)

  • code : Barcode encoding data value.

    Servlet Parameter: code; Default Value: ""

  • supplementCode : 2 or 5 digits Barcode supplement data for EAN-8, EAN-13, UPC-A, UPC-E, ISBN, ISSN only.

    Servlet Parameter: supplement-code; Default Value: ""

  • addChecksum : Apply Checksum digit at the end of some linear barcode value.

    Servlet Parameter: add-checksum; Default Value: false

Barcode Size

  • barcodeUnit : Unit of meature for all size related properties. 0: Pixel (default); 1: CM; 2: Inch.

    Servlet Parameter: barcode-unit; Default Value: 0 (UOM_PIXEL)

  • barWidth : bar module width, default is 3 pixel

    Servlet Parameter: bar-width; Default Value: 3

  • barHeight : bar module height, default is 60 pixel

    Servlet Parameter: bar-height; Default Value: 60

  • leftMargin : generated barcode image left margin

    Servlet Parameter: left-margin; Default Value: 0.0f

  • rightMargin : generated barcode image right margin

    Servlet Parameter: right-margin; Default Value: 0.0f

  • topMargin : generated barcode image top margin

    Servlet Parameter: top-margin; Default Value: 0.0f

  • bottomMargin : generated barcode image bottom margin

    Servlet Parameter: bottom-margin; Default Value: 0.0f

  • resolution : generated barcode image resolution in dpi

    Servlet Parameter: resolution; Default Value: 72 dpi

  • rotate : barcode rotate angle, valid values: 0 (ROTATE_0), 1 (ROTATE_90), 2 (ROTATE_180), 3 (ROTATE_270)

    Servlet Parameter: rotate; Default Value: 0 (ANGLE_0)

  • barcodeWidth

    Servlet Parameter: barcode-width; Default Value: 0

  • barcodeHeight

    Servlet Parameter: barcode-height; Default Value: 0

Barcode Text Style

  • displayText : set true to draw barcode value text under the barcode

    Servlet Parameter: display-text; Default Value: true

  • textFont : drawn barcode value text font style

    Servlet Parameter: text-font; Default Value: new Font("Arial", Font.PLAIN, 11)

For Codabar

  • codabarStartChar : Codabar start char, should be one of 'A', 'B', 'C', 'D'

    Servlet Parameter: codabar-start-char; Default Value: 'A'

  • codabarStopChar : Codabar stop char, should be one of 'A', 'B', 'C', 'D'

    Servlet Parameter: codabar-stop-char; Default Value: 'A'

  • barRatio : Wide vs narrow bar width ratio, valid range 2.0 - 3.0 inclusive.

    Servlet Parameter: bar-ratio; Default Value: 2.0f

Java Barcode Generator Supporting Barcode Symbology Types

Quick Links