Java Barcode Generator, .NET Barcode Generator for C#, ASP.NET, VB.NET
HOME BARCODE FOR JAVA PURCHASE


Developer Guide > Code-39 Generation Guide

Code-39 Barcode Sample Code & Barcode Property Settings



1. Generate Code-39 in Java Class

The following Java code illustrates how to generate a Code-39 barcode in a Java class

	Linear barcode = new Linear();
        barcode.setType(Linear.CODE39);
        // barcode data to encode
        barcode.setData("CODE39-123456789012");

        // wide bar width vs narrow bar width ratio
        barcode.setN(3.0f);

        // unit of measure for X, Y, LeftMargin, RightMargin, TopMargin, BottomMargin
        barcode.setUOM(Linear.UOM_PIXEL);
        // barcode module width in pixel
        barcode.setX(3f);
        // barcode module height in pixel
        barcode.setY(75f);

        barcode.setLeftMargin(0f);
        barcode.setRightMargin(0f);
        barcode.setTopMargin(0f);
        barcode.setBottomMargin(0f);
        // barcode image resolution in dpi
        barcode.setResolution(72);

        // disply human readable text under the barcode
        barcode.setShowText(true);
        // human reable text font style
        barcode.setTextFont(new Font("Arial", 0, 12));
        //  ANGLE_0, ANGLE_90, ANGLE_180, ANGLE_270
        barcode.setRotate(Linear.ANGLE_0);

        barcode.setAddCheckSum(true);

        barcode.renderBarcode("c://barcode.gif");
        
        // generate barcode to BufferedImage object
        BufferedImage bufferedImage = linear.renderBarcode();

	// generate barcode to byte[] object
	byte[] barcodeBytes = linear.renderBarcodeToBytes();

	// render barcode on Graphics2D
	Graphics2D g = ...
	Rectangle2D rectangle = ... 
	linear.renderBarcode(g, rectangle);
	
	// generate barcode and output to OutputStream object
	OutputStream outputStream = ...
	linear.renderBarcode(outputStream);




2. 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: How to control barcode size?
    • 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


3. All Barcode Types