Barcode-Lib4J requires Java 9+

Java Class «ImplCode128C»  –  Generate Code 128 C Barcode

All Implemented Interfaces:
Cloneable

public class ImplCode128C extends ImplCode128
Implementation of Code 128 C. To generate instances, please use one of the newInstance static methods in the Barcode class.

Code 128 C is a subset of Code 128, optimized for compact encoding of numeric data. Compactness is achieved by encoding digits in pairs, which allows the encoding to take up only half the space. A minor drawback is that the encoded number must always consist of an even number of digits. However, odd-length numbers can be automatically prefixed with a leading '0' to ensure an even length.

Code 128 C uses an internal checksum which is contained only within the barcode symbol and is not displayed in the plaintext representation of the barcode.

Note: Encoding the same number with Code 128 and Code 128 C will produce exactly the same barcode. However, Code 128 C can be used, for example, to provide additional validation of numeric values by throwing an exception if the value to be encoded contains non-numeric characters.

  • Method Details

    • setContent

      public void setContent(String content, boolean autoComplete, boolean appendOptionalChecksum) throws BarcodeException
      Sets the number to be encoded in the barcode.

      If the length of the number is odd and autoComplete is true, the method automatically adds a '0' at the beginning, as an odd length number cannot be encoded by Code 128 C according to the requirements of the barcode format.

      Alternatively, when autoComplete is set to false, the method expects that the number is provided with the correct length. In certain scenarios, this can be used to double check the integrity of the number. For example, if it's assumed that the number is even in length, but the actual length turns out to be odd, this will be indicated by the method throwing a BarcodeException.

      Overrides:
      setContent in class ImplCode128
      Parameters:
      content - the number to be encoded in the Code 128 C barcode
      autoComplete - whether to automatically add '0' at the beginning of the number if its length is odd
      appendOptionalChecksum - has no function, as Code 128 C uses a fixed internal checksum which is not optional
      Throws:
      BarcodeException - if the content is empty, contains non-numeric characters, or the length is odd while autoComplete is false