Java Code 39 Generator Size Setting Tutorial

sample source code to generate linear Code 39 images and adjust barcode size in Java


  • Easily generate high quality Code 39 images with setting the Code 39 size setting options on any operating system with a JVM
  • Permanent license with the purchase of the developer license
  • Servlets are compatible with all browsers, easy to embed in HTML as an image with the tag and can be used to add server-side barcode generator capability to a dedicated Web server
  • Complete Library Source code for Java Barcode is provided with purchase of Unlimited Developer License with Source Code
  • Check sum digit of Code 39 image can be automatically computed
  • Code 39 image width in Java can be changed with Y (bar height), barcodeHeight, topMargin and bottomMargin
  • Text margin, text font can influence the size of Code 39 in Java

Code 39, also known as Alpha39, Code 3 of 9, Code 3/9, Type 39, USS Code 39, or USD-3, is the first alpha-numeric linear barcode symbology used world-wide.

For more details on how to set the image Code 39 in Java, please go to Java Code 39 image setting;

For more details on how to encode the Code 39 valid data set and data length, please go to Java Code 39 data encoding.


Code 39 in Java Size Concerned Properties

Code 39 Width Related Settings in Java

  • I: The space between 2 characters in code 39. This a multiple of X module (bar width).
  • N: Wide bar vs narrow bar ratio. Valid values are 2.0 - 3.0 inclusive, default is 2.0.
  • X: Width of Code 39 bar module (narrow bar), default is 1 pixel.
  • barcodeWidth: Generated Code 39 barcode image width.
  • leftMargin: Code 39 image left margin size.
  • rightMargin: Code 39 image right margin size.

Code 39 Height Related Settings in Java

  • Y: Height of Code 39 bar module, default is 30 pixel.
  • barcodeHeight: Generated Code 39 barcode image height.
  • topMargin: Code 39 image top margin size.
  • bottomMargin: Code 39 image bottom margin size.

Other Code 39 Size Setting Properties in Java

  • autoResize: Auto resize the generated Code 39 barcode image.
  • uom: Unit of meature for all size related settings in the Java barcode library. Valid values: 0: pixel; 1: inch; 2: cm.
  • textMargin: Space between barcode and printed barcode data, default is 6 pixel.
  • textFont: Code 39 text (printed below barcode) font style.


How to Implement Code 39 Size Setting Properties in Java Projects

Other Code 39 Size Setting Properties in Java

Java Code 39 generator supports all Code 39 size related solution to specify the Code 39 images generated in Java. After purchasing the Code 39 generator for Java, please install and set up it, then copy the following code into your Java IntelliJ IDEA:

      Code39 barcode = new Code39();
barcode.setData("123456789012");
barcode.setExtension(false);

Then, modify the following properties you may need:

How to set I to change the Code 39 size in Java

      barcode.setI(1.0f);

How to Set N for adjusting the Code 39 in Java

      barcode.setN(3.0f);

How to Change the total size of Java Code 39 - Uom

      barcode.setUom(IBarcode.UOM_PIXEL);

How to Change the Width of Code 39 with Java

      barcode.setX(1f);
barcode.setLeftMargin(0f);
barcode.setRightMargin(0f);

During setting the Code 39 width with the above properties, you need to pay attention that after you set a fixed bar width (X), an auto barcode width - minimum barcode width will be set in Java applications. However, if the set barcodeWidth value is less than the minimum barcode width, the created Code 39 image width in Java will be the minimum value. If the set barcodeWith is larger than the minimum one, the extra width will be added on the right and left margins in Java.

How to Adjust the height of Code 39 using Java

      barcode.setY(75f);
barcode.setTopMargin(0f);
barcode.setBottomMargin(0f);

For Code 39 image height adjustment, the situation is as same as Code 39 image width adjustment.

How to Change the Text of Java Code 39

      //Set the show text to be true for adjustment in Java
      barcode.setShowText(true);
barcode.setTextFont(new Font("Arial", 0, 12));
barcode.setTextMargin(6);




OnBarcode is a market-leading provider of barcode generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides high quality tutorials and guides for various linear, 2d barcode information, such as C# Barcode, QR Code C#, QR Code VB.NET, QR Code ASP.NET, QR Code .NET, ASP.NET Barcode. OnBarcode barcode products are supported by RasterEdge .NET HTML5 Document Viewer high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.