Java Barcode Generator, .NET Barcode Generator for C#, ASP.NET, VB.NET
HOME PURCHASE SITEMAP COMPANY

Home > Java Barcode Generator > Java Barcode Generation Guide > Java Code-39 Barcodes Generator

Download Java Barcode Trial

Java Code-39 Barcodes Generator Guide

Code-39 Bar Code Generation Guide in Java class, J2EE, Jasper Reports, iReport & Eclipse BIRT

  • Easily generate Code-39 barcodes in Java applications
  • Compatible with the latest Code-39 ISO specification [ISO/IEC 16388 (Second edition 2007-05-15)]
  • Generate high quality Code-39 images in JPEG, GIF & PNG formats
  • 100% build in Java, compatible with JDK 1.4 and later version
  • Generate Code-39 barcodes on any platforms with a Java virtual machine
  • Generate Code-39 in Jasper Reports & iReport
  • Generate Code-39 in Eclipse BIRT
  • Mature Java Barcode Generator library since 2003
  • Royalty-free and perpetual developer license


Quick Navigate

 

1. Java Code-39 Barcode Introduction

Code-39 is also known as ANSI/AIM Code 39, ANSI/AIM Code 39, Uniform Symbology Specification Code 39, USS Code 39, USS 39, Code 3/9, Code 3 of 9, USD-3, LOGMARS, Alpha39, Code 39 Extended, and Code 39 Full ASCII

Compatibility: Barcode for Java library is compatible with the latest Code-39 ISO specification [ISO/IEC 16388 (Second edition 2007-05-15)]

Code 39, the first alpha-numeric symbology to be developed, is still widely used-especially in non-retail environments. It is the standard bar code used by the United States Department of Defense, and is also used by the Health Industry Bar Code Council (HIBCC).


Sample of a Code 39 Barcode

Sample of a Code 39 Extension Barcode


 

2. Java Code-39 Encoding Data Scope

Java Code 39 Generator encodes the following chars:
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Uppercase letters (A - Z)
  • - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)

Java Code 39 Extension Generator encodes:
  • all 128 ASCII characters


 

3. How to Generate Code-39 Barcode in Java Class?

The following Java code illustrates how to create a Code-39 barcode, and output to various formats

1            Linear linear = new Linear(); 
2            linear.setType(Linear.CODE39); 
3            linear.setData("CODE39"); 
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 Code-39 (line 2)
  • Set Code 39 barcode data to encode (line 3)
  • Encode generated code-39 barcode into gif image file (line 4)
  • Generate Code-39 and output to BufferedImage object (line 5)
  • Generate Code-39 in bitmap and output to byte[] (line 6)
  • Generate Code-39 and draw to defined area (Rectangle2D) on Graphics2D (line 7-9)
  • Generate Code-39 and output to OutputStream (line 10-11)



 

4. How to Generate Barcode Code-39 Image in Java Web Applications?

There are two methods to create Code-39 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
      http://YourDomain:Port/barcode/linear?Data=123456789&Type=CODE39


    • 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=123456789&Type=CODE39" />

      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
      1            Linear linear = new Linear(); 
      2            linear.setData("123456789"); 
      3            linear.setType(Linear.CODE39); 
      4            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" />



 

5. How to Generate Barcode Code-39 Image in Jasper Reports, iReport, Eclipse BIRT?




 

6. Java Code-39 Property Settings

  • Set the type property to Linear.CODE39 or Linear.CODE39EX
    Servlet URL Parameter: "Type". Value: 3 for Code-39, 4 for Code-39 extension. Sample: &Type=3
  • Set the data property with the value to encode.
    Type is String.
    • Valid Data Scope for Code 39 (BarcodeType.CODE39):
      • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
      • Uppercase letters (A - Z)
      • - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)
    • Valid Data Scope for Code 39 extension (BarcodeType.CODE39EX):
      • all 128 ASCII characters
    • Sample: barcode.setData("CODE39-123456789012")
    Servlet URL Parameter: Data.
  • addCheckSum property is optional. Modulo 43 will be applied, if addCheckSum property is true.
    Default is false.
    Servlet URL Parameter: "AddCheckSum". Values: "t" (true), "f" (false). Sample: &AddCheckSum=t
  • Set N property, Wide bar vs Narrow bar ratio. Valid values are from 2.0f to 3.0f, inclusive.
    Default is 2.0f.
    Servlet URL Parameter: N. Sample: &N=3
  • Set showStartStopInText property. Whether display * in the begin and end of Code 39 data
    Default is true.
    Servlet URL Parameter: ShowStartStop. Values: "t" (true), "f" (false). Sample: &ShowStartStop=t
  • Set the processTilde property to true, if you want use the tilde character "~" to specify special characters in the encoding data. Default is false.
    Format of the tilde:
    • ~NNN: is used to represent the ASCII character with the value of NNN. NNN is from 000 - 255.

    Servlet Parameter: "ProcessTilde". Values: "t" (true), "f" (false). Sample: &ProcessTilde=t
  • 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
  • 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
  • With rotate property, you can display barcode horizontally or vertically.
    Value can be
    • 0 (Linear.ANGLE_0),
    • 1 (Linear.ANGLE_90),
    • 2 (Linear.ANGLE_180),
    • 3 (Linear.ANGLE_270)

    Default value is 0.
    Servlet URL Parameter: "Rotate". Sample: &Rotate=0


 

7. How to Set Generated Barcode Code-39 Image Size?





All Java Barcode Types/Symbologies


 









   Copyright 2010 BarcodeLib.com. Java Barcode, Barcode Java, Java Barcode Generator. All rights reserved.