Ask Your Question
3

Can ZXing generate GS1-128 barcodes using Java?

asked 2022-08-16 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-31 16:00:00 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-16 11:00:00 +0000

Seen: 10 times

Last updated: Mar 31 '22