CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-zxing--core

Core barcode encoding/decoding library supporting 17 formats including QR Code, Data Matrix, Aztec, PDF 417, and various 1D barcodes

Pending
Overview
Eval results
Files

oned.mddocs/reference/

1D Barcode Support

Complete support for 8 different 1D barcode formats including Code 39, Code 93, Code 128, Codabar, EAN-8, EAN-13, UPC-A, UPC-E, ITF (Interleaved 2 of 5), and RSS (GS1 DataBar) variants. Each format has dedicated reader and writer implementations with format-specific configuration options. 1D barcodes are linear symbologies widely used in retail, logistics, healthcare, and manufacturing.

Capabilities

Base Classes

OneDReader

Abstract base class for all 1D barcode readers. Provides common functionality for scanning horizontal rows and detecting 1D patterns.

/**
 * Abstract base class for reading 1D barcodes.
 * Implements common row scanning logic and pattern detection.
 * Subclasses implement format-specific decoding.
 */
public abstract class OneDReader implements Reader {
    /**
     * Locates and decodes a 1D barcode in an image.
     *
     * @param image Binary bitmap representation of the image
     * @return Result containing decoded text and metadata
     * @throws NotFoundException If no barcode is found in the image
     * @throws ChecksumException If barcode checksum validation fails
     * @throws FormatException If barcode format rules are violated
     */
    @Override
    public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException;

    /**
     * Locates and decodes a 1D barcode with configuration hints.
     *
     * @param image Binary bitmap representation of the image
     * @param hints Map of DecodeHintType to configuration values
     * @return Result containing decoded text and metadata
     * @throws NotFoundException If no barcode is found in the image
     * @throws ChecksumException If barcode checksum validation fails
     * @throws FormatException If barcode format rules are violated
     */
    @Override
    public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
        throws NotFoundException, ChecksumException, FormatException;

    /**
     * Resets any internal state.
     */
    @Override
    public void reset();
}

MultiFormatOneDReader

Multi-format 1D barcode reader that attempts to decode using all supported 1D formats or a subset specified via hints.

/**
 * Multi-format 1D barcode reader implementation.
 * Attempts to decode using all 1D formats or formats specified in hints.
 * Extends OneDReader to leverage common 1D scanning logic.
 */
public final class MultiFormatOneDReader extends OneDReader {
    /**
     * Creates a MultiFormatOneDReader with default settings.
     * Will attempt all supported 1D formats.
     */
    public MultiFormatOneDReader();

    /**
     * Creates a MultiFormatOneDReader with configuration hints.
     *
     * @param hints Map of DecodeHintType to configuration values
     *              - POSSIBLE_FORMATS: Limit to specific 1D formats
     *              - TRY_HARDER: Spend more time for better accuracy
     */
    public MultiFormatOneDReader(Map<DecodeHintType,?> hints);
}

Code 39

Variable-length alphanumeric format supporting uppercase letters, digits, and limited special characters. Widely used in non-retail applications including automotive, defense, and healthcare.

/**
 * Reader for Code 39 barcodes.
 * Supports optional check digit and extended mode for full ASCII.
 */
public final class Code39Reader extends OneDReader {
    /**
     * Creates Code39Reader with default settings (no check digit, no extended mode).
     */
    public Code39Reader();

    /**
     * Creates Code39Reader with check digit validation option.
     *
     * @param usingCheckDigit If true, validates and strips check digit
     */
    public Code39Reader(boolean usingCheckDigit);

    /**
     * Creates Code39Reader with full configuration.
     *
     * @param usingCheckDigit If true, validates and strips check digit
     * @param extendedMode If true, interprets extended Code 39 (full ASCII)
     */
    public Code39Reader(boolean usingCheckDigit, boolean extendedMode);
}

/**
 * Writer for Code 39 barcodes.
 * Encodes uppercase letters, digits, and symbols: - . $ / + % SPACE
 */
public final class Code39Writer implements Writer {
    /**
     * Creates Code39Writer.
     */
    public Code39Writer();

    /**
     * Encodes contents into Code 39 BitMatrix.
     *
     * @param contents String to encode (uppercase A-Z, 0-9, and - . $ / + % space)
     * @param format Must be BarcodeFormat.CODE_39
     * @param width Preferred width in pixels
     * @param height Preferred height in pixels
     * @return BitMatrix representation
     * @throws IllegalArgumentException If contents contains invalid characters
     */
    @Override
    public BitMatrix encode(String contents, BarcodeFormat format, int width, int height);
}

Usage Example:

// Reading Code 39
Reader reader = new Code39Reader(true, false); // With check digit
Result result = reader.decode(bitmap);

// Writing Code 39
Writer writer = new Code39Writer();
BitMatrix matrix = writer.encode("ABC-123", BarcodeFormat.CODE_39, 300, 100);

Code 93

Compact alphanumeric format more efficient than Code 39. Supports full ASCII character set through extended mode. Built-in error checking with two check digits.

/**
 * Reader for Code 93 barcodes.
 * Automatically validates built-in check digits.
 */
public final class Code93Reader extends OneDReader {
    /**
     * Creates Code93Reader.
     */
    public Code93Reader();
}

/**
 * Writer for Code 93 barcodes.
 * Automatically adds required check digits.
 */
public final class Code93Writer implements Writer {
    /**
     * Creates Code93Writer.
     */
    public Code93Writer();
}

Code 128

High-density variable-length format supporting full ASCII character set. Widely used in shipping and packaging. Excellent data efficiency with automatic mode switching.

/**
 * Reader for Code 128 barcodes.
 * Supports automatic mode switching between A, B, and C.
 */
public final class Code128Reader extends OneDReader {
    /**
     * Creates Code128Reader.
     */
    public Code128Reader();
}

/**
 * Writer for Code 128 barcodes.
 * Automatically selects optimal encoding modes.
 * Supports GS1-128 format via hints.
 */
public final class Code128Writer implements Writer {
    /**
     * Creates Code128Writer.
     */
    public Code128Writer();

    /**
     * Encodes contents with hints support.
     *
     * @param hints Supports:
     *              - FORCE_CODE_SET (Integer): Force specific code set (A=0, B=1, C=2)
     *              - GS1_FORMAT (Boolean): Use GS1-128 format with FNC1
     *              - CODE128_COMPACT (Boolean): Use compact encoding
     */
    @Override
    public BitMatrix encode(String contents, BarcodeFormat format, int width, int height,
                          Map<EncodeHintType,?> hints);
}

Codabar

Variable-length numeric format with start/stop characters. Commonly used in libraries, blood banks, and package tracking. Supports digits and symbols: - $ : / . +

/**
 * Reader for Codabar barcodes.
 */
public final class CodaBarReader extends OneDReader {
    /**
     * Creates CodaBarReader.
     */
    public CodaBarReader();
}

/**
 * Writer for Codabar barcodes.
 * Requires start/stop characters (A, B, C, or D).
 */
public final class CodaBarWriter implements Writer {
    /**
     * Creates CodaBarWriter.
     */
    public CodaBarWriter();
}

EAN-8

Fixed 8-digit product barcode (International Article Number, shortened). Used for small product packages. Last digit is check digit.

/**
 * Reader for EAN-8 barcodes.
 * Automatically validates check digit.
 */
public final class EAN8Reader extends UPCEANReader {
    /**
     * Creates EAN8Reader.
     */
    public EAN8Reader();
}

/**
 * Writer for EAN-8 barcodes.
 * Automatically calculates and appends check digit if not provided.
 */
public final class EAN8Writer implements Writer {
    /**
     * Creates EAN8Writer.
     */
    public EAN8Writer();
}

EAN-13

Fixed 13-digit product barcode (International Article Number, standard). Widely used for retail products worldwide. Last digit is check digit.

/**
 * Reader for EAN-13 barcodes.
 * Automatically validates check digit.
 */
public final class EAN13Reader extends UPCEANReader {
    /**
     * Creates EAN13Reader.
     */
    public EAN13Reader();
}

/**
 * Writer for EAN-13 barcodes.
 * Automatically calculates and appends check digit if not provided.
 */
public final class EAN13Writer implements Writer {
    /**
     * Creates EAN13Writer.
     */
    public EAN13Writer();
}

UPC-A

Fixed 12-digit product barcode (Universal Product Code, standard). Primary barcode format for retail in North America. Last digit is check digit.

/**
 * Reader for UPC-A barcodes.
 * Actually wraps EAN13Reader since UPC-A is a subset of EAN-13.
 */
public final class UPCAReader implements Reader {
    /**
     * Creates UPCAReader.
     */
    public UPCAReader();
}

/**
 * Writer for UPC-A barcodes.
 * Automatically calculates and appends check digit if not provided.
 */
public final class UPCAWriter implements Writer {
    /**
     * Creates UPCAWriter.
     */
    public UPCAWriter();
}

UPC-E

Compressed 6-digit version of UPC-A (zero-suppressed format). Used for small product packages. Expands to full UPC-A when decoded.

/**
 * Reader for UPC-E barcodes.
 * Automatically expands to full UPC-A format.
 */
public final class UPCEReader extends UPCEANReader {
    /**
     * Creates UPCEReader.
     */
    public UPCEReader();
}

/**
 * Writer for UPC-E barcodes.
 * Automatically compresses from UPC-A format.
 */
public final class UPCEWriter implements Writer {
    /**
     * Creates UPCEWriter.
     */
    public UPCEWriter();
}

ITF (Interleaved 2 of 5)

Numeric-only format requiring even number of digits. Used in warehouse and distribution. High density for numeric data, interleaves pairs of digits.

/**
 * Reader for ITF barcodes.
 * Decodes interleaved digit pairs.
 */
public final class ITFReader extends OneDReader {
    /**
     * Creates ITFReader.
     */
    public ITFReader();
}

/**
 * Writer for ITF barcodes.
 * Requires even number of digits.
 */
public final class ITFWriter implements Writer {
    /**
     * Creates ITFWriter.
     */
    public ITFWriter();
}

RSS (GS1 DataBar)

GS1 standard formats for small items and supplementary data. More compact than traditional UPC/EAN. Supports additional information like expiration dates and batch numbers.

/**
 * Reader for RSS-14 (GS1 DataBar) barcodes.
 * Decodes 14-digit GTIN values.
 */
public final class RSS14Reader extends AbstractRSSReader {
    /**
     * Creates RSS14Reader.
     */
    public RSS14Reader();
}

/**
 * Reader for RSS Expanded (GS1 DataBar Expanded) barcodes.
 * Supports variable-length data with Application Identifiers.
 */
public final class RSSExpandedReader extends AbstractRSSReader {
    /**
     * Creates RSSExpandedReader.
     */
    public RSSExpandedReader();
}

Format Comparison

FormatTypeChar SetCheck DigitUse Case
Code 39VariableAlphanumericOptionalAutomotive, Defense, Healthcare
Code 93VariableFull ASCIIBuilt-in (2)Logistics, Canadian Post
Code 128VariableFull ASCIIBuilt-inShipping, Packaging, GS1-128
CodabarVariableNumeric + SymbolsOptionalLibraries, Blood Banks
EAN-8Fixed (8)NumericRequiredSmall Products
EAN-13Fixed (13)NumericRequiredRetail Products (International)
UPC-AFixed (12)NumericRequiredRetail Products (North America)
UPC-EFixed (6/8)NumericRequiredSmall Products
ITFVariable (even)NumericOptionalWarehouse, Cartons
RSS-14Fixed (14)Numeric (GTIN)Built-inSmall Items, Coupons
RSS ExpandedVariableAlphanumericBuilt-inGrocery, Healthcare

Common Configuration

Decode Hints for 1D Barcodes

Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);

// Limit to specific 1D formats
hints.put(DecodeHintType.POSSIBLE_FORMATS,
    Arrays.asList(BarcodeFormat.CODE_128, BarcodeFormat.EAN_13));

// Enable more thorough scanning
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

// Assume Code 39 has check digit
hints.put(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT, Boolean.TRUE);

// Return Codabar start/stop characters
hints.put(DecodeHintType.RETURN_CODABAR_START_END, Boolean.TRUE);

// Assume GS1 format (Code 128)
hints.put(DecodeHintType.ASSUME_GS1, Boolean.TRUE);

// Allowed EAN/UPC extension lengths
hints.put(DecodeHintType.ALLOWED_EAN_EXTENSIONS, new int[]{2, 5});

Encode Hints for 1D Barcodes

Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);

// Set margin/quiet zone
hints.put(EncodeHintType.MARGIN, 10);

// Force specific Code 128 code set
hints.put(EncodeHintType.FORCE_CODE_SET, 1); // Force Code Set B

// Enable GS1-128 format
hints.put(EncodeHintType.GS1_FORMAT, Boolean.TRUE);

// Enable compact Code 128
hints.put(EncodeHintType.CODE128_COMPACT, Boolean.TRUE);

Best Practices

Format Selection:

  • Retail Products: EAN-13 (international), UPC-A (North America)
  • Small Products: EAN-8, UPC-E
  • Shipping/Logistics: Code 128 (best density), Code 39 (compatibility)
  • Numeric Only: ITF (warehouse), RSS-14 (small items)
  • Full ASCII: Code 128 (recommended), Code 93 (compact)
  • Legacy Systems: Code 39 (widest compatibility)

Quality Requirements:

  • X-Dimension: Minimum 0.33mm (13 mils) for retail
  • Quiet Zones: Critical for 1D barcodes (10x on both sides minimum)
  • Print Quality: Grade A or B (verify with barcode verifier)
  • Contrast: Minimum 70% (dark bars on light background)
  • Height: Minimum 15% of barcode length (more for Code 39)

Reading Tips:

  • Scan perpendicular to bars for best results
  • Ensure adequate lighting
  • Use TRY_HARDER hint for difficult scans
  • For damaged barcodes, try multiple scan angles

Encoding Best Practices:

  • Always include check digits (automatic in most formats)
  • Provide adequate quiet zones (margins)
  • Use appropriate format for data type (numeric vs. alphanumeric)
  • Test with actual scanners before production
  • Verify compliance with industry standards (GS1, etc.)

See Also

  • Core Reading and Writing - Basic reading and writing operations
  • Configuration Hints - 1D-specific hints (ASSUME_CODE_39_CHECK_DIGIT, RETURN_CODABAR_START_END, etc.)
  • Barcode Formats - All supported 1D formats overview
  • Exception Handling - Handling decode exceptions
  • Result Handling - Working with 1D barcode results

Install with Tessl CLI

npx tessl i tessl/maven-com-google-zxing--core@3.5.1

docs

index.md

tile.json