Barcode
public sealed class BarcodeStand-alone barcode generator (no ZPL needed): set Barcode.Symbology and Barcode.Code, then export as bitmap/PNG, vector PDF/SVG/EPS, or draw onto any SKCanvas.
Not thread-safe: a
Barcode is a mutable settings object; use one instance per thread (instances on different threads are independent and deterministic). Invalid data throws ArgumentException, FormatException or NotSupportedException.Online ausprobieren auf zplCloud.com: Barcode zu ZPL · QR-Code zu ZPL
Constructors
| Signature | Description |
|---|---|
# Barcode() |
Properties
| Property | Type | Description |
|---|---|---|
AddChecksum { get; set; } | bool | |
Alignment { get; set; } | BarcodeAlignment | Position inside the target box (FitProportional / AutoSize). |
AntiAlias { get; set; } | bool | Anti-aliased bars and modules (default off: crisp edges at whole pixels). |
ArtBarImagePattern { get; set; } | SKBitmap | Image tiled as fill pattern of the bars / modules (instead of Barcode.ForeColor). |
AztecErrorCorrection { get; set; } | int | Aztec error correction in percent of the data (5..95, default 23). |
AztecFormat { get; set; } | AztecFormat | Aztec format (Auto = full range, as bwip-js; ZXing chooses when no other Aztec option is set). |
AztecLayers { get; set; } | int | Aztec layers (compact 1..4, full 1..32; 0 = automatic). |
BackColor { get; set; } | SKColor | |
BarArt { get; set; } | BarArt | Motif in the upper part of the bars of linear codes (EAN/UPC, Code 128, GS1-128, ITF …). Default none. |
BarArtHeightPercent { get; set; } | double | Part of the bar height the motif may use, 5–40 % (default 30): the rest stays plain bars. |
BarArtImage { get; set; } | SKBitmap | Silhouette for BarArt.Image: dark, opaque pixels keep the bar, stretched over the motif band. |
BarHeight { get; set; } | double | Bar height of linear codes (2D codes ignore it; their modules are square). |
BarWidth { get; set; } | double | Narrow bar / module width. |
BarWidthReduction { get; set; } | double | Bar width reduction (ink spread compensation) in Barcode.Unit: every dark bar/module gets narrower by this amount. |
BarWidthReductionPercent { get; set; } | double | Bar width reduction in percent of the module width (added to Barcode.BarWidthReduction). |
BearerBarWidth { get; set; } | double | |
BearerBars { get; set; } | BearerBarStyle | Bearer bars (ITF-14 frame or horizontal rules). |
BorderColor { get; set; } | SKColor | |
BorderRadius { get; set; } | double | Corner radius of the border (and background) in Barcode.Unit. |
BorderWidth { get; set; } | double | Border line width in Barcode.Unit (0 = none). |
ByteEncodingName { get; set; } | string | Character encoding of the data bytes, e.g. "ISO-8859-5", "Shift_JIS", "UTF-8": the text is converted with that encoding and an ECI designator (Eci.FromEncodingName) is placed in front. Supported by QR Code, Aztec and MaxiCode; other symbologies with ECI support throw NotSupportedException. |
CodabarStartChar { get; set; } | char? | Codabar start character A–D when the data has none (null = A). |
CodabarStopChar { get; set; } | char? | Codabar stop character A–D when the data has none (null = A). |
Code { get; set; } | string | |
Code128Subset { get; set; } | Code128Subset | Code 128 start code set: A/B/C start in that set and keep it unless the data contains ZPL invocation codes (>5, >6, >7); Auto = shortest encoding. |
Code16KMode { get; set; } | Code16KMode | Code 16K start mode (initial code set); Auto = BWIPP's choice. |
Code16KRows { get; set; } | int | Minimum number of Code 16K rows (2..16, 0 = automatic). |
CodeEncoding { get; set; } | CodeEncoding | |
CodeFormatPattern { get; set; } | string | Pattern applied to Barcode.Code before encoding (same syntax as Barcode.TextFormatPattern). |
CompositeComponent { get; set; } | CompositeComponent | Composite component of the GS1 composite symbologies. |
DataBarSegmentsPerRow { get; set; } | int | |
DataMatrixDmre { get; set; } | bool | Allow the DMRE (ISO/IEC 21471) rectangles in the automatic rectangular size selection. |
DataMatrixEncodation { get; set; } | DataMatrixEncodation | Data Matrix encodation scheme. Non-Auto values use that scheme for every character it can represent (ASCII for the rest) instead of the look-ahead optimisation. |
DataMatrixSize { get; set; } | string | Fixed Data Matrix size "RxC" (rows × columns), e.g. "24x24", "16x48"; DMRE sizes such as "8x48" are allowed. Null = smallest fitting. |
DisplayChecksum { get; set; } | bool | Show computed check digits in the human readable text (default true). |
DisplayStartStopChar { get; set; } | bool? | Show Code 39 '*' / Codabar start and stop characters (null = symbology default). |
DotCodeAspectRatio { get; set; } | double | DotCode width:height ratio for the automatic size (0 = 1.5). |
DotCodeColumns { get; set; } | int | DotCode columns (at least 5, 0 = automatic). |
DotCodeRows { get; set; } | int | DotCode rows (at least 5, 0 = automatic). With both rows and columns their sum must be odd. |
Dpi { get; set; } | int | Resolution for raster output and unit conversion. |
ErrorBehavior { get; set; } | BarcodeErrorBehavior | Error behaviour of the outputs (Barcode.Encode always throws). |
FinderShape { get; set; } | FinderShape | |
FontSize { get; set; } | double | Font size of the human readable text in points (0 = automatic, proportional to the module). |
ForeColor { get; set; } | SKColor | |
Gs1StrictValidation { get; set; } | bool | GS1-128: check AI values against the GS1 syntax rules (lint) instead of plain AI parsing. |
GuardBarHeight { get; set; } | double? | EAN/UPC guard bar extension below the bars in Barcode.Unit (null = half the text height). |
GuardBars { get; set; } | bool | Extend EAN/UPC guard bars into the text area. |
HalftoneColor { get; set; } | bool | Colour sub-modules from the image (PNG, SVG, PDF) instead of black-and-white error diffusion (thermal printers). |
static HalftoneEnabled { get; set; } | bool | Opt-in for halftone QR (Barcode.HalftoneImage, HalftoneImageData) for the whole process. Default false: a halftone image is ignored, the code is printed as a plain QR Code and Barcode.CheckReadability reports AR011. Set it to true to render halftone QR codes; checking that this rendering method may be used in the countries where your labels are produced or used is your responsibility. |
HalftoneImage { get; set; } | SKBitmap | Halftone QR: image worked into the code. Each module is split into 3 × 3 sub-modules; the centre sub-module and all finder, separator, timing, alignment, format and version modules keep the data, the other sub-modules follow the image (error diffusion to black and white, or the image colours with Barcode.HalftoneColor). QR codes only (Symbology.QrCode, Symbology.Gs1QrCode, Symbology.DinSpecQrCode); error correction is set to H, the module must be at least 3 pixels. Null = off. Only applied while Barcode.HalftoneEnabled is true. |
HalftoneStrength { get; set; } | double | Share of the 8 outer sub-modules of each data module that follow the image, 0–1 (0 = plain code, 1 = all 8; the centre always keeps the data). Default 0.6 (5 of 8). Corners are given to the image first. |
HanXinErrorCorrection { get; set; } | int | Han Xin error correction level 1..4 (L1..L4). |
HanXinMode { get; set; } | HanXinMode | Han Xin: force numeric, text or binary encodation for the whole message. |
HanXinVersion { get; set; } | int | Han Xin version 1..84 (0 = smallest fitting). |
HumanReadableAlignment { get; set; } | HumanReadableAlignment | |
HumanReadableText { get; set; } | string | Text instead of the encoded data (null = automatic, incl. check digits). |
ItfHMarks { get; set; } | bool | ITF-14: draw "H" marks in the quiet zones left and right of the symbol (inside the bearer frame). |
JabCodeColors { get; set; } | int | JAB Code colours: 4, 8 (default), 16, 32, 64, 128 or 256. |
JabCodeErrorCorrection { get; set; } | int | JAB Code error correction level 0..10 (default 6). |
JabCodeMask { get; set; } | int | JAB Code mask 0..7 (-1 = best). |
LightMarginIndicator { get; set; } | bool | EAN/UPC light margin indicators ('<' / '>') in the quiet zones (GS1 General Specifications). |
LogoBackground { get; set; } | bool | Draw a plate in Barcode.BackColor behind the logo. |
LogoImage { get; set; } | SKBitmap | Logo drawn in the center of 2D codes (QR: error correction is forced to H). |
LogoOpacity { get; set; } | double | Logo opacity 0..1. |
LogoPosition { get; set; } | LogoPosition | |
LogoSizePercent { get; set; } | double | Logo width in percent of the symbol width (without quiet zone). |
MagnificationFactor { get; set; } | double? | EAN/UPC magnification factor 0.8–2.0 (GS1 General Specifications): sets the module to 0.330 mm × factor and the bar height to 22.85 mm × factor (EAN-13, UPC-A, UPC-E and ISBN/ISSN/ISMN/JAN) or 18.23 mm × factor (EAN-8, JAN-8), overriding Barcode.BarWidth and Barcode.BarHeight. Null = off. |
MaxiCodeMode { get; set; } | int | |
MaxiCodePixelAligned { get; set; } | bool | MaxiCode: draw the hexagons without anti-aliasing with centres snapped to whole pixels (crisp thermal output). |
MicroPdf417Columns { get; set; } | int | MicroPDF417 columns (1..4, 0 = automatic). |
MicroPdf417Rows { get; set; } | int | MicroPDF417 rows (per the ISO size table, 0 = automatic). |
MicroQrVersion { get; set; } | int | Micro QR version 1..4 (M1..M4), 0 = smallest fitting. |
ModuleShape { get; set; } | ModuleShape | |
MsiChecksum { get; set; } | MsiChecksum? | MSI check digits (null = mod 10, the encoder default). |
Padding { get; set; } | BarcodePadding | Margin around the barcode (outside the quiet zone, inside the border) in Barcode.Unit. |
Pdf417AspectRatio { get; set; } | double | PDF417 width:height ratio of the symbol (without quiet zone) used to choose the column count when Barcode.Pdf417Columns is 0 (0 = BWIPP default). |
Pdf417Columns { get; set; } | int | |
Pdf417Compaction { get; set; } | Pdf417Compaction | PDF417 compaction: Auto (text/numeric/byte optimisation), all Numeric, or all Binary (byte). |
Pdf417Rows { get; set; } | int | PDF417 rows (3..90, 0 = automatic). |
Pdf417SecurityLevel { get; set; } | int | |
PharmacodeSpacing { get; set; } | int | Pharmacode space between bars in modules (default 2). |
PharmacodeThickBar { get; set; } | int | Pharmacode thick bar width in modules (default 3). |
PharmacodeThinBar { get; set; } | int | Pharmacode thin bar width in modules (default 1). |
PostalBarSpacing { get; set; } | double | Postal codes: gap between bars in modules (default 1.5). |
PostalShortBarRatio { get; set; } | double | POSTNET/PLANET short bar height as fraction of Barcode.BarHeight (default 0.4). |
PostalTrackerRatio { get; set; } | double | 4-state postal codes: tracker height as fraction of Barcode.BarHeight (default 1/3). |
ProcessTilde { get; set; } | bool | Tilde escapes: ~~ tilde, ~dNNN byte, ~1 FNC1 (GS1 when first, else GS), ~2IICC structured append (index, count, 2 digits each), ~eNNNNNN / ~5NNNNNN ECI. |
QrEncodingMode { get; set; } | QrEncodingMode | QR Code data mode: Auto (BWIPP segmentation) or one segment in the given mode. Kanji encodes the text as Shift JIS double-byte characters. |
QrErrorCorrection { get; set; } | char | |
QrMask { get; set; } | int | QR mask pattern 0–7 (-1 = automatic). |
QrVersion { get; set; } | int | QR version 1–40 (0 = smallest fitting). |
QuietZone { get; set; } | int? | Quiet zone in modules on every side (null: 10 for linear codes and Codablock F, 4 for 2D and the other stacked codes; Code 16K and Code 49 additionally carry their 10X/1X quiet zones inside the symbol). |
ReadabilityMinContrast { get; set; } | double | Smallest contrast between Barcode.ForeColor and Barcode.BackColor (luminance difference 0–1) below which Barcode.CheckReadability reports a finding. Default 0.4 (ISO symbol contrast grade C). |
ReadabilityMinModulePixels { get; set; } | double | Smallest module size in pixels for shaped modules below which Barcode.CheckReadability reports a finding. Default 4. |
RectMicroQrVersion { get; set; } | string | rMQR version, e.g. "R7x43" … "R17x139"; null = smallest area. |
RightToLeft { get; set; } | bool | Draw the human readable text right to left (character order reversed). |
Rotation { get; set; } | int | Rotation in degrees (0, 90, 180, 270). |
Size { get; } | SKSize | Size of the output in pixels before rotation: the natural barcode plus Barcode.Padding and border, or the target box of Barcode.Sizing. |
Sizing { get; set; } | BarcodeSizing | Sizing mode; needs Barcode.TargetWidth and Barcode.TargetHeight (in Barcode.Unit, final orientation). |
StructuredAppendInfo { get; set; } | StructuredAppendInfo | Structured append for QR, Data Matrix, Aztec, MaxiCode and PDF417 (null = none). |
Supplement { get; set; } | string | EAN/UPC 2- or 5-digit supplement drawn right of the main symbol. |
SupplementSpacing { get; set; } | int | EAN/UPC supplement gap in modules (default 9). |
SupplementTopMargin { get; set; } | double? | EAN/UPC supplement: distance from the top of the main bars to the top of the supplement bars (in Barcode.Unit; null = the height of the text line). |
Symbology { get; set; } | Symbology | |
TargetHeight { get; set; } | double | Output height for Barcode.Sizing (in Barcode.Unit). |
TargetWidth { get; set; } | double | Output width for Barcode.Sizing (in Barcode.Unit). |
TextColor { get; set; } | SKColor | |
TextFormatPattern { get; set; } | string | Format for the human readable text: a composite format such as "{0:### ### ###}" (applied to the numeric value when the text is numeric) or a mask where A a 9 # X x * ? take the next character and everything else is literal, e.g. "AAA-999". |
TextPosition { get; set; } | BarcodeTextPosition | |
TextStrikeout { get; set; } | bool | |
TextUnderline { get; set; } | bool | |
Tlc39Gap { get; set; } | int | TLC39: gap between the MicroPDF417 and the Code 39 part in modules (ZPL ^BT uses 2). |
Tlc39MicroPdfRowHeight { get; set; } | int | TLC39: height of one MicroPDF417 row in modules (ZPL ^BT h2; default 2). |
Typeface { get; set; } | SKTypeface | |
UltracodeErrorCorrection { get; set; } | int | Ultracode error correction level 1..5 (EC1..EC5, default 2). |
Unit { get; set; } | BarcodeUnit | Unit of Barcode.BarWidth, Barcode.BarHeight, Barcode.BearerBarWidth. |
UseQuietZoneForText { get; set; } | bool | Linear codes: the human readable text uses the quiet zone below (or above) the bars instead of adding height. |
VerifyReadability { get; set; } | bool | Decode artistic codes (module/finder shapes, logo, halftone image, bar motif) after rendering at Barcode.Dpi with zxing-cpp and ZXing.Net. A halftone image or bar motif that does not read is weakened step by step (down to the plain code). Results are cached per content and settings. Default true. |
WideRatio { get; set; } | double | Wide-to-narrow ratio for two-width codes (2.0–3.0). |
Methods
| Method Signature | Returns | Description |
|---|---|---|
# CheckReadability() | BarcodeReadability | Decodes the rendered symbol (rotation 0, without the human-readable text, camera-blurred) at Barcode.Dpi with zxing-cpp and ZXing.Net and compares the data; zxing-cpp decides (ZXing.Net where it is not available). A halftone image or bar motif that does not read is weakened in steps (75 %, 50 %, 25 %, off); the result names what is printed. Cached per content and settings. |
static # ClearReadabilityCache() | void | Clears the readability cache (tests, memory pressure). |
# Draw(SKCanvas canvas, float x = 0, float y = 0) | void | Draws the barcode with vector primitives onto any canvas (raster, PDF, SVG). |
# Encode() | BarcodeMatrix | Encodes Barcode.Code to modules. |
# IsCodeValid() | bool | True when Barcode.Code can be encoded with the current settings. |
# IsCodeValid(out string error) | bool | True when Barcode.Code can be encoded; otherwise error describes why. |
# StructuredAppend(int index, int count, int parity = -1, string? fileId = default) | Barcode | Sets structured append: symbol index (1-based) of count. |
# ToBitmap() | SKBitmap | |
# ToEps() | string | Encapsulated PostScript (vector bars, text in Courier). |
# ToEps(EpsColorMode colorMode) | string | Encapsulated PostScript in the given color model (RGB, CMYK or grayscale operators). |
# ToHtmlImgTag(HtmlImageFormat format = HtmlImageFormat.Png, string? alt = default) | string | HTML <img> tag with the barcode as data URI. |
# ToJpeg(int quality = 95) | byte[] | |
# ToPcl() | byte[] | PCL5 raster page at Barcode.Dpi. |
# ToPcx() | byte[] | 1-bit PCX at Barcode.Dpi. |
# ToPdf() | byte[] | Vector PDF with the physical size of the barcode. |
# ToPng() | byte[] | |
# ToSvg() | string | Vector SVG. |
# ToTiff(TiffCompression compression = TiffCompression.PackBits) | byte[] | 1-bit TIFF (via RasterExport) at Barcode.Dpi. |
# ToWebp(int quality = 95) | byte[] | |
# ToZplGraphic(int x = 0, int y = 0) | string | The barcode as ZPL graphic (^GFA) at the given position, e.g. for symbologies without a ZPL command. |

