Skip to main content

Industrial 2 of 5

  • 2 minutes to read

Industrial 2 of 5 is a low-density, numeric-only barcode symbology introduced in the 1960s. It is primarily used in legacy industrial and logistics systems, including warehouse sorting, photo finishing, and airline ticket identification.

The symbology encodes data using alternating wide and narrow bars and is optimized for fast scanning in controlled environments. It does not support alphanumeric characters.

Industrial 2 of 5, DevExpress Barcode Generation API for Java

Refer to the following page for additional information: https://en.wikipedia.org/wiki/Industrial_2_of_5

Configure Industrial 2 of 5 Settings

Use the Industrial2of5Options class to configure Industrial 2 of 5 barcode settings.

Method Description
setCalculateChecksum(boolean value) Specifies whether to calculate and append a checksum digit for error detection.
setWideNarrowRatio(float value) Specifies the ratio between wide and narrow bars in the barcode symbol.

The following code snippet creates an Industrial 2 of 5 barcode and customizes its encoding parameters:

import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Industrial2of5Options options = new Industrial2of5Options();
        options.setCalculateChecksum(true);
        options.setWideNarrowRatio(3);
        options.setPadding(new Padding(10));
        options.setShowText(true);
        options.setWidth(600);

        Path outputDir = Path.of("output");
        Files.createDirectories(outputDir);

        try (FileOutputStream fileStream = new FileOutputStream(
                outputDir.resolve("industrial2of5.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "12345670",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}

Fluent API

Use the Industrial2of5OptionsBuilder class to configure Industrial 2 of 5 barcode settings with the Fluent API.

The following code snippet creates an Industrial 2 of 5 barcode and customizes its encoding parameters with the Fluent API:

import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Industrial2of5Options options = Industrial2of5OptionsBuilder.create()
            .withCalculateChecksum(true)
            .withWideNarrowRatio(3)
            .withPadding(new Padding(10))
            .withShowText(true)
            .withWidth(600)
            .build();

        Path outputDir = Path.of("output");
        Files.createDirectories(outputDir);

        try (FileOutputStream fileStream = new FileOutputStream(
                outputDir.resolve("industrial2of5.png").toFile());
                BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
                    barcodeGenerator.export(
                            "12345670",
                            fileStream,
                            DXImageFormat.getPng());
        }
    }
}
See Also