Barcode Class

Represents a generated barcode as a boolean matrix of modules.

public sealed class Barcode

Properties

NameDescription
HeightGets the height (number of rows).
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

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

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.

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.