Barcode Class
Represents a generated barcode as a boolean matrix of modules.
public sealed class BarcodeProperties
| Name | Description |
|---|---|
| Height | Gets the height (number of rows). |
| IsStacked | Gets whether the barcode is a stacked symbol: several rows of bars, whose heights are part of the symbol. |
| Text | Gets the human-readable interpretation of the barcode: the encoded data as it is printed under the bars. |
| Type | Gets the type of barcode. |
| Width | Gets the width (number of columns). |
Height
Barcode.csIsStacked
Barcode.csGets whether the barcode is a stacked symbol: several rows of bars, whose heights are part of the symbol.
public bool IsStacked { get; }Property value
Remarks
A linear barcode has one row, as high as the renderer draws it (BarcodeRenderOptions.ModuleHeight, ConsoleRenderOptions.BarHeight). A stacked barcode, such as BarcodeType.Gs1DataBarStacked, has one row per module of height: a row of bars 5 modules high is 5 identical rows, and the renderers draw each row as high as a module is wide.
Text
Barcode.csGets the human-readable interpretation of the barcode: the encoded data as it is printed under the bars.
public string Text { get; }Property value
Remarks
It includes the characters the barcode adds: the check digit of EAN-8, EAN-13 and UPC-A (followed by a space and the add-on when there is one), the Mod 43 check character of Code 39 when it is included, and the start and stop characters of Codabar. It does not include the Code 39 and Code 93 start and stop characters.
Type
Barcode.csWidth
Barcode.csIndexers
| Name | Description |
|---|---|
| this[int, int] | Gets whether the module at the specified position is dark. |
this[int, int]
Barcode.csMethods
| Name | Description |
|---|---|
| CreateCodabar(string, char, char) | Creates a Codabar barcode from the specified data. |
| CreateCode128(string) | Creates a Code 128 barcode from the specified data. |
| CreateCode39(string, bool) | Creates a Code 39 barcode from the specified data. |
| CreateCode93(string) | Creates a Code 93 barcode from the specified data. |
| CreateEan13(string, string?) | Creates an EAN-13 barcode from the specified data. |
| CreateEan8(string, string?) | Creates an EAN-8 barcode from the specified data. |
| CreateGs1128(ReadOnlySpan<Gs1Element>) | Creates a GS1-128 barcode from GS1 element strings. |
| CreateGs1DataBar(string) | Creates a GS1 DataBar Omnidirectional barcode from a GTIN. |
| CreateGs1DataBarExpanded(ReadOnlySpan<Gs1Element>) | Creates a GS1 DataBar Expanded barcode from GS1 element strings. |
| CreateGs1DataBarExpandedStacked(int, ReadOnlySpan<Gs1Element>) | Creates a GS1 DataBar Expanded Stacked barcode from GS1 element strings: GS1 DataBar Expanded in rows of segmentsPerRow segments. |
| CreateGs1DataBarLimited(string) | Creates a GS1 DataBar Limited barcode from a GTIN that starts with 0 or 1. |
| CreateGs1DataBarStacked(string) | Creates a GS1 DataBar Stacked barcode from a GTIN: GS1 DataBar in two rows 5 and 7 modules high. |
| CreateGs1DataBarStackedOmnidirectional(string) | Creates a GS1 DataBar Stacked Omnidirectional barcode from a GTIN: GS1 DataBar in two rows 33 modules high. |
| CreateItf(string) | Creates an Interleaved 2 of 5 (ITF) barcode from the specified data. |
| CreateUpcA(string, string?) | Creates a UPC-A barcode from the specified data. |
| CreateUpcE(string, string?) | Creates a UPC-E barcode: a UPC-A number of number system 0 or 1, without some of its zeros. |
CreateCodabar(string, char, char)
Barcode.csCreateCode128(string)
Barcode.csCreates a Code 128 barcode from the specified data.
Parameters
datastring- The data to encode: ASCII characters (U+0000 to U+007F), control characters included.
Returns
Barcode A new Barcode instance.
Remarks
The encoder chooses the code sets: C for runs of digits, A for control characters, B for lowercase letters, with a SHIFT when the other code set is needed for a single character.
CreateCode39(string, bool)
Barcode.csCreateCode93(string)
Barcode.csCreateEan13(string, string?)
Barcode.csCreates an EAN-13 barcode from the specified data.
CreateEan8(string, string?)
Barcode.csCreates an EAN-8 barcode from the specified data.
CreateGs1128(ReadOnlySpan<Gs1Element>)
Barcode.csCreates a GS1-128 barcode from GS1 element strings.
public static Barcode CreateGs1128(params scoped ReadOnlySpan<Gs1Element> elements)Parameters
elementsReadOnlySpan<Gs1Element>- The element strings, in the order they are encoded.
Returns
Barcode A new Barcode instance, whose Barcode.Text is the human-readable interpretation: each application identifier in parentheses, followed by its data.
Exceptions
ArgumentExceptionelementsis empty, containsnull, or needs more than the 48 data characters of a GS1-128 symbol (application identifiers and separators included).
Remarks
The symbol starts with the FNC1 function character that identifies GS1-128, and a FNC1 separator follows each element whose application identifier does not have a predefined length, except the last one. The parentheses of the human-readable interpretation are not encoded. A reader returns the data with the separators as the ASCII group separator character (U+001D) and the symbology identifier ]C1.
Put the elements of variable length last to save separators. Barcode.CreateCode128 never adds FNC1: the symbols it creates are not GS1-128 symbols, even when the data looks like element strings.
CreateGs1DataBar(string)
Barcode.csCreates a GS1 DataBar Omnidirectional barcode from a GTIN.
Parameters
datastring- The GTIN: 13 digits (without check digit) or 14 digits (with check digit). Add leading zeros to a GTIN-8, GTIN-12 or GTIN-13.
Returns
Barcode A new Barcode instance, whose Barcode.Text is the GTIN as the element string (01) followed by its 14 digits.
Exceptions
ArgumentExceptiondatais not a GTIN of 13 or 14 digits, or its check digit is invalid.
Remarks
The symbol is 96 modules wide; GS1 DataBar Omnidirectional is at least 33 modules high. Rendered 13 modules high (13 times the module width), it is GS1 DataBar Truncated, which has the same modules.
CreateGs1DataBarExpanded(ReadOnlySpan<Gs1Element>)
Barcode.csCreates a GS1 DataBar Expanded barcode from GS1 element strings.
public static Barcode CreateGs1DataBarExpanded(params scoped ReadOnlySpan<Gs1Element> elements)Parameters
elementsReadOnlySpan<Gs1Element>- The element strings, in the order they are encoded.
Returns
Barcode A new Barcode instance, whose Barcode.Text is the human-readable interpretation: each application identifier in parentheses, followed by its data.
Exceptions
ArgumentExceptionelementsis empty, containsnull, or does not fit in a symbol.
Remarks
The symbol holds up to 74 digits or 41 letters. It is shorter when the data starts with a GTIN (01), and shorter still for a GTIN of a variable measure trade item (starting with 9) followed by its weight (310n, 320n) and a date (11, 13, 15, 17), or by its price (392n, 393n).
CreateGs1DataBarExpandedStacked(int, ReadOnlySpan<Gs1Element>)
Barcode.csCreates a GS1 DataBar Expanded Stacked barcode from GS1 element strings: GS1 DataBar Expanded in rows of segmentsPerRow segments.
public static Barcode CreateGs1DataBarExpandedStacked(int segmentsPerRow, params scoped ReadOnlySpan<Gs1Element> elements)Parameters
segmentsPerRowint- The number of segments (symbol characters) per row: an even number from 2 to 20. The last row may have fewer.
elementsReadOnlySpan<Gs1Element>- The element strings, in the order they are encoded.
Returns
Barcode A new stacked Barcode instance: rows 34 modules high, separated by 3 rows of separator patterns.
Exceptions
ArgumentOutOfRangeExceptionsegmentsPerRowis not an even number from 2 to 20.ArgumentExceptionelementsis empty, containsnull, or does not fit in a symbol.
CreateGs1DataBarLimited(string)
Barcode.csCreates a GS1 DataBar Limited barcode from a GTIN that starts with 0 or 1.
Parameters
datastring- The GTIN: 13 digits (without check digit) or 14 digits (with check digit), the first one 0 or 1.
Returns
Barcode A new Barcode instance, 74 modules wide, whose Barcode.Text is the GTIN as the element string (01) followed by its 14 digits.
Exceptions
ArgumentExceptiondatais not a GTIN of 13 or 14 digits, its check digit is invalid, or its first digit is not 0 or 1.
CreateGs1DataBarStacked(string)
Barcode.csCreates a GS1 DataBar Stacked barcode from a GTIN: GS1 DataBar in two rows 5 and 7 modules high.
Parameters
datastring- The GTIN: 13 digits (without check digit) or 14 digits (with check digit).
Returns
Barcode A new stacked Barcode instance, 50 modules wide and 13 modules high.
Exceptions
ArgumentExceptiondatais not a GTIN of 13 or 14 digits, or its check digit is invalid.
CreateGs1DataBarStackedOmnidirectional(string)
Barcode.csCreates a GS1 DataBar Stacked Omnidirectional barcode from a GTIN: GS1 DataBar in two rows 33 modules high.
Parameters
datastring- The GTIN: 13 digits (without check digit) or 14 digits (with check digit).
Returns
Barcode A new stacked Barcode instance, 50 modules wide and 69 modules high.
Exceptions
ArgumentExceptiondatais not a GTIN of 13 or 14 digits, or its check digit is invalid.
CreateItf(string)
Barcode.csCreateUpcA(string, string?)
Barcode.csCreates a UPC-A barcode from the specified data.
CreateUpcE(string, string?)
Barcode.csCreates a UPC-E barcode: a UPC-A number of number system 0 or 1, without some of its zeros.
Parameters
datastring- The UPC-E number: 6 digits (number system 0, without check digit), 7 digits (the number system and 6 digits) or 8 digits (the number system, 6 digits and the check digit). Or the UPC-A number to compress: 11 digits (without check digit) or 12 digits (with check digit).
extensionstring?- Optional UPC/EAN 2-digit or 5-digit supplemental extension.
Returns
Barcode A new Barcode instance, whose Barcode.Text is the 8 digits of the UPC-E number.
Exceptions
ArgumentExceptiondatahas another length, characters other than digits, a number system other than 0 or 1, an invalid check digit, or is a UPC-A number with no UPC-E form.
Remarks
The check digit is the one of the UPC-A number. A UPC-A number has a UPC-E form when it has the zeros UPC-E removes: for instance the UPC-A number 03600000029 is the UPC-E number 0360290, and 03600029145 has no UPC-E form. A UPC-A number has a single UPC-E form: the other 6 digits that stand for it are rejected.