Barcode Class

Represents a generated barcode as a boolean matrix of modules.

public sealed class Barcode

Properties

NameDescription
HeightGets the height (number of rows).
IsStackedGets whether the barcode is a stacked symbol: several rows of bars, whose heights are part of the symbol.
TextGets the human-readable interpretation of the barcode: the encoded data as it is printed under the bars.
TypeGets the type of barcode.
WidthGets the width (number of columns).

Gets the height (number of rows).

public int Height { get; }

Property value

int

IsStacked

Barcode.cs

Gets whether the barcode is a stacked symbol: several rows of bars, whose heights are part of the symbol.

public bool IsStacked { get; }

Property value

bool

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.

Gets the human-readable interpretation of the barcode: the encoded data as it is printed under the bars.

public string Text { get; }

Property value

string

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.

Gets the type of barcode.

public BarcodeType Type { get; }

Property value

BarcodeType

Gets the width (number of columns).

public int Width { get; }

Property value

int

Indexers

NameDescription
this[int, int]Gets whether the module at the specified position is dark.

this[int, int]

Barcode.cs

Gets whether the module at the specified position is dark.

public bool this[int row, int column] { get; }

Parameters

row int
The row index (0-based).
column int
The column index (0-based).

Property value

bool

Methods

NameDescription
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.cs

Creates a Codabar barcode from the specified data.

public static Barcode CreateCodabar(string data, char startCharacter = 'A', char stopCharacter = 'B')

Parameters

data string
The data to encode.
startCharacter char
The start character (A, B, C, or D).
stopCharacter char
The stop character (A, B, C, or D).

Returns

Barcode A new Barcode instance.

CreateCode128(string)

Barcode.cs

Creates a Code 128 barcode from the specified data.

public static Barcode CreateCode128(string data)

Parameters

data string
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.cs

Creates a Code 39 barcode from the specified data.

public static Barcode CreateCode39(string data, bool includeChecksum = false)

Parameters

data string
The data to encode.
includeChecksum bool
true to append the optional Mod 43 checksum character; otherwise, false.

Returns

Barcode A new Barcode instance.

CreateCode93(string)

Barcode.cs

Creates a Code 93 barcode from the specified data.

public static Barcode CreateCode93(string data)

Parameters

data string
The data to encode.

Returns

Barcode A new Barcode instance.

CreateEan13(string, string?)

Barcode.cs

Creates an EAN-13 barcode from the specified data.

public static Barcode CreateEan13(string data, string? extension = null)

Parameters

data string
The data to encode (12 digits without checksum, or 13 digits with checksum).
extension string?
Optional UPC/EAN 2-digit or 5-digit supplemental extension.

Returns

Barcode A new Barcode instance.

CreateEan8(string, string?)

Barcode.cs

Creates an EAN-8 barcode from the specified data.

public static Barcode CreateEan8(string data, string? extension = null)

Parameters

data string
The data to encode (7 digits without checksum, or 8 digits with checksum).
extension string?
Optional UPC/EAN 2-digit or 5-digit supplemental extension.

Returns

Barcode A new Barcode instance.

CreateGs1128(ReadOnlySpan<Gs1Element>)

Barcode.cs

Creates a GS1-128 barcode from GS1 element strings.

public static Barcode CreateGs1128(params scoped ReadOnlySpan<Gs1Element> elements)

Parameters

elements ReadOnlySpan<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

ArgumentException
elements is empty, contains null, 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.cs

Creates a GS1 DataBar Omnidirectional barcode from a GTIN.

public static Barcode CreateGs1DataBar(string data)

Parameters

data string
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

ArgumentException
data is 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.cs

Creates a GS1 DataBar Expanded barcode from GS1 element strings.

public static Barcode CreateGs1DataBarExpanded(params scoped ReadOnlySpan<Gs1Element> elements)

Parameters

elements ReadOnlySpan<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

ArgumentException
elements is empty, contains null, 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.cs

Creates 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

segmentsPerRow int
The number of segments (symbol characters) per row: an even number from 2 to 20. The last row may have fewer.
elements ReadOnlySpan<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

ArgumentOutOfRangeException
segmentsPerRow is not an even number from 2 to 20.
ArgumentException
elements is empty, contains null, or does not fit in a symbol.

CreateGs1DataBarLimited(string)

Barcode.cs

Creates a GS1 DataBar Limited barcode from a GTIN that starts with 0 or 1.

public static Barcode CreateGs1DataBarLimited(string data)

Parameters

data string
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

ArgumentException
data is 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.cs

Creates a GS1 DataBar Stacked barcode from a GTIN: GS1 DataBar in two rows 5 and 7 modules high.

public static Barcode CreateGs1DataBarStacked(string data)

Parameters

data string
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

ArgumentException
data is not a GTIN of 13 or 14 digits, or its check digit is invalid.

CreateGs1DataBarStackedOmnidirectional(string)

Barcode.cs

Creates a GS1 DataBar Stacked Omnidirectional barcode from a GTIN: GS1 DataBar in two rows 33 modules high.

public static Barcode CreateGs1DataBarStackedOmnidirectional(string data)

Parameters

data string
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

ArgumentException
data is not a GTIN of 13 or 14 digits, or its check digit is invalid.

CreateItf(string)

Barcode.cs

Creates an Interleaved 2 of 5 (ITF) barcode from the specified data.

public static Barcode CreateItf(string data)

Parameters

data string
The data to encode (digits only, even number of digits).

Returns

Barcode A new Barcode instance.

CreateUpcA(string, string?)

Barcode.cs

Creates a UPC-A barcode from the specified data.

public static Barcode CreateUpcA(string data, string? extension = null)

Parameters

data string
The data to encode (11 digits without checksum, or 12 digits with checksum).
extension string?
Optional UPC/EAN 2-digit or 5-digit supplemental extension.

Returns

Barcode A new Barcode instance.

CreateUpcE(string, string?)

Barcode.cs

Creates a UPC-E barcode: a UPC-A number of number system 0 or 1, without some of its zeros.

public static Barcode CreateUpcE(string data, string? extension = null)

Parameters

data string
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).
extension string?
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

ArgumentException
data has 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.