Java Class «ImplITF» – Generate Interleaved 2 of 5 Barcode
- All Implemented Interfaces:
Cloneable
newInstance
static methods in the Barcode
class.
Interleaved 2 of 5 is a widely used barcode format for compact encoding of numeric data. Compactness is achieved by encoding digits in pairs, allowing 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.
Interleaved 2 of 5 can also be used with an optional check digit for additional error detection and data integrity. The check digit can be appended to the encoded content and can optionally be displayed in the human readable text. When the check digit is used, it changes the total length of the encoded content, which may affect the evenness of the total length. This should be considered when preparing content for encoding.
This class extends the abstract class LineageTwoWidth
, as Interleaved 2 of 5 is a
type of two-width barcode. See the linked class description for more information.
Barcode scanner configuration: When using Interleaved 2 of 5 without a check digit, it is advisable to configure the scanner to expect a constant number of characters. This is because the start and stop patterns are not unique, making the format vulnerable. If the scanner enters or exits the code at a point that resembles a start or stop pattern, the code may be scanned incompletely.
-
Field Summary
Fields inherited from class de.vwsoft.barcodelib4j.oned.LineageTwoWidth
DEFAULT_RATIO
-
Method Summary
Modifier and TypeMethodDescriptionvoid
setContent
(String content, boolean autoComplete, boolean appendOptionalChecksum) Sets the number to be encoded in the barcode.Methods inherited from class de.vwsoft.barcodelib4j.oned.LineageTwoWidth
getRatio, setRatio
Methods inherited from class de.vwsoft.barcodelib4j.oned.Barcode
clone, draw, draw, draw, getAddOn, getContent, getFont, getText, getTextOffset, isFontSizeAdjusted, isTextOnTop, isTextVisible, newInstance, newInstance, setAddOn, setCustomText, setFont, setFontSizeAdjusted, setTextOffset, setTextOnTop, setTextVisible, supportsAddOn, supportsAutoCompletion, supportsCustomText, supportsTextOnTop
-
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
istrue
, the method automatically adds a '0' at the beginning, as an odd length number cannot be encoded by Interleaved 2 of 5 according to the requirements of the barcode format.Alternatively, when
autoComplete
is set tofalse
, 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 aBarcodeException
.Using an optional check digit affects the total length of the number and can determine whether the total number of digits is even or odd. This should be considered when providing content for encoding.
- Specified by:
setContent
in classBarcode
- Parameters:
content
- the number to be encoded in the Interleaved 2 of 5 barcodeautoComplete
- whether to automatically add '0' at the beginning of the number if its length is oddappendOptionalChecksum
- whether to append an optional check digit to the number- Throws:
BarcodeException
- if the content is empty, contains non-numeric characters, or the length is odd whileautoComplete
isfalse
-