Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, ZXing can generate GS1-128 barcodes using Java. The GS1-128 symbology is also known as EAN-128 or UCC-128 and is a standardized format that is widely used for product labeling in supply chain applications. To generate GS1-128 barcodes using Java, you can use the GS1Code128Writer class provided by the ZXing library. Here is an example code snippet that generates a GS1-128 barcode:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.oned.EAN13Writer;
import com.google.zxing.oned.UPCAWriter;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import java.util.HashMap;
import java.util.Map;

public class GenerateBarcode {

    public static void main(String[] args) {
        String gs1Data = "(01)12345678901234(10)ABCDEFG";
        Map<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        GS1Code128Writer writer = new GS1Code128Writer();
        try {
            BitMatrix bitMatrix = writer.encode(gs1Data, BarcodeFormat.CODE_128, 400, 200, hints);
            // TODO: Render the BitMatrix as an image or print the barcode
        } catch (WriterException e) {
            e.printStackTrace();
        }
    }
}

In this example, the gs1Data string represents the GS1 data to be encoded in the barcode, and the hints map provides additional encoding options such as the character set and error correction level. The GS1Code128Writer class is used to encode the GS1 data as a Code 128 barcode, which is the basis for the GS1-128 symbology. Finally, the resulting BitMatrix can be rendered as an image or printed to generate the actual barcode.