Skip to content

TTMSFNCWXBarcode

The TTMSFNCWXBarcode is a component to generate and display barcodes in over 100 standard symbologies. It uses the bwip-js JavaScript library, which is a JavaScript port of the widely used BWIPP PostScript barcode library.

Notice

With the default settings this component requires an internet connection. If you'd like to run the component in an offline environment, please change the LibraryLocation property. Read more about this at the Loading modes section of this documentation.


Creating barcodes

To generate a barcode, set the BarcodeType and Text properties. Both can be set at design time or at runtime. The barcode is re-rendered automatically whenever a property changes.

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCWXBarcode1.BarcodeType := bciCode128;
  TMSFNCWXBarcode1.Text := '012345678905';
end;

Input validation

Each barcode symbology accepts only specific character sets and length ranges. Setting a Text value that is invalid for the selected BarcodeType raises an Exception. Always wrap assignments in a try/except block when the input comes from user data.

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    TMSFNCWXBarcode1.BarcodeType := bciEAN13;
  except on E: Exception do
    ShowMessage('BarcodeType error: ' + E.Message);
  end;

  try
    TMSFNCWXBarcode1.Text := '5901234123457';
  except on E: Exception do
    ShowMessage('Text error: ' + E.Message);
  end;
end;

Supported barcode types

The BarcodeType property accepts values of type TTMSFNCWXBarcodeType. The table below groups all supported symbologies.

Linear (1-D) barcodes

Enum value Symbology
bciCode128 Code 128
bciCode39 Code 39
bciCode39Ext Code 39 Extended
bciCode93 Code 93
bciCode93Ext Code 93 Extended
bciCode11 Code 11
bciCode32 Code 32 (Italian pharma)
bciCode2of5 Code 2 of 5
bciInterleaved2of5 Interleaved 2 of 5
bciCOOP2of5 COOP 2 of 5
bciDatalogic2of5 Datalogic 2 of 5
bciIATA2of5 IATA 2 of 5
bciIndustrial2of5 Industrial 2 of 5
bciMatrix2of5 Matrix 2 of 5
bciCodabar Codabar
bciTelepen Telepen
bciTelepenNumeric Telepen Numeric
bciPharmacode Pharmacode
bciPharmacode2 Pharmacode 2-Track
bciPlessey Plessey
bciMSI MSI (Modified Plessey)
bciChannelCode Channel Code
bciDaft DAFT
bciFlattermarken Flattermarken
bciBC412 BC412
bciCustom1DSymb Custom 1-D Symbol (raw)
bciSymbol Symbol

GS1 and retail

Enum value Symbology
bciEAN13 EAN-13
bciEAN13Comp EAN-13 Composite
bciEAN8 EAN-8
bciEAN8Copm EAN-8 Composite
bciEAN14 EAN-14
bciEAN2 EAN-2 Supplement
bciEAN5 EAN-5 Supplement
bciUPCA UPC-A
bciUPCAComp UPC-A Composite
bciUPCE UPC-E
bciUPCEComp UPC-E Composite
bciITF14 ITF-14
bciSSCC18 SSCC-18
bciGS1128 GS1-128
bciGS1128Comp GS1-128 Composite
bciGS1DataBarExp GS1 DataBar Expanded
bciGS1DataBarExpComp GS1 DataBar Expanded Composite
bciGS1DataBarExpStack GS1 DataBar Expanded Stacked
bciGS1DataBarExpStackComp GS1 DataBar Expanded Stacked Composite
bciGS1DataBarLimited GS1 DataBar Limited
bciGS1DataBarLimitedComp GS1 DataBar Limited Composite
bciGS1DataBarOmni GS1 DataBar Omnidirectional
bciGS1DataBarOmniComp GS1 DataBar Omnidirectional Composite
bciGS1DataBarStacked GS1 DataBar Stacked
bciGS1DataBarStackComp GS1 DataBar Stacked Composite
bciGS1DataBarStackOmni GS1 DataBar Stacked Omnidirectional
bciGS1DataBarStackOmniComp GS1 DataBar Stacked Omnidirectional Composite
bciGS1DataBarTruncated GS1 DataBar Truncated
bciGS1DataBarTruncComp GS1 DataBar Truncated Composite
bciGS1Comp2DComp GS1 Composite (2D Composite)
bciGS1NACoupon GS1 North American Coupon

2-D barcodes

Enum value Symbology
bciDataMatrix Data Matrix
bciDataMatrixRect Data Matrix Rectangular
bciDataMatrixRectExt Data Matrix Rectangular Extension
bciGS1DataMatrix GS1 Data Matrix
bciGS1DataMatrixRect GS1 Data Matrix Rectangular
bciAztecCode Aztec Code
bciAztecCodeCompact Aztec Code Compact
bciAztecRunes Aztec Runes
bciDotCode DotCode
bciGS1DotCode GS1 DotCode
bciHanXin Han Xin Code
bciPDF417 PDF417
bciPDF417Comp PDF417 Compact
bciMicroPDF417 Micro PDF417
bciMaxiCode MaxiCode
bciUltracode Ultracode
bciCodeOne Code One

Postal barcodes

Enum value Symbology
bciAusPost Australia Post
bciJapanPost Japan Post
bciKix KIX (Netherlands Post)
bciOneCode USPS Intelligent Mail (OneCode)
bciPlanet USPS PLANET
bciPostnet USPS POSTNET
bciRoyalMail Royal Mail 4-State
bciMailmark Royal Mail Mailmark
bciIdentcode Deutsche Post Identcode
bciLeitcode Deutsche Post Leitcode

ISBN, ISSN, ISMN

Enum value Symbology
bciISBN ISBN
bciISSN ISSN
bciISMN ISMN

Stacked symbologies

Enum value Symbology
bciCodablockF Codablock F
bciCode16K Code 16K
bciCode49 Code 49
bciPosiCode PosiCode

PZN (Pharmazentralnummer)

Enum value Symbology
bciPZN PZN (7- or 8-digit, see Settings.PZNVariant)

HIBC (Health Industry Bar Code)

Enum value Symbology
bciHIBCAztecCode HIBC Aztec Code
bciHIBCCodablockF HIBC Codablock F
bciHIBCCode128 HIBC Code 128
bciHIBCCode39 HIBC Code 39
bciHIBCDataMatrix HIBC Data Matrix
bciHIBCDataMatrixRect HIBC Data Matrix Rectangular
bciHIBCMicroPDF417 HIBC Micro PDF417
bciHIBCPDF417 HIBC PDF417

Retrieving barcodes

Asynchronous retrieval (event-based)

Implement the OnGetBarcode event to receive the rendered barcode as a TTMSFNCBitmap every time it is re-generated:

procedure TForm1.TMSFNCWXBarcode1GetBarcode(Sender: TObject;
  ABitmap: TTMSFNCBitmap);
begin
  // Save the barcode image to a file
  ABitmap.SaveToFile('C:\Temp\barcode.png');
end;

The ABitmap is owned by the event; do not free it inside the handler.

Synchronous retrieval

Use the GetBarcode(AText: string): TTMSFNCBitmap method to obtain a barcode image synchronously. The caller is responsible for freeing the returned bitmap.

Platform limitation

Synchronous execution via ExecuteJavaScriptSync is not supported on Android. Use the event-based approach on Android devices.

procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TTMSFNCBitmap;
begin
  bmp := TMSFNCWXBarcode1.GetBarcode('5901234123457');
  if Assigned(bmp) then
  try
    bmp.SaveToFile('C:\Temp\barcode.png');
  finally
    bmp.Free;
  end;
end;

Image format

The ImageFormat property controls whether the barcode is rendered as a PNG raster image or as an SVG vector image:

Value Description
bifPNG (default) Raster PNG rendered on an HTML <canvas> element
bifSVG Scalable SVG rendered as an inline <span> element

SVG output is resolution-independent and scales perfectly at any size, making it ideal for print workflows.

TMSFNCWXBarcode1.ImageFormat := bifSVG;

Customization

Bar color and background

TMSFNCWXBarcode1.BarColor        := gcNavy;
TMSFNCWXBarcode1.BackgroundColor := gcLightcyan;

BackgroundColor defaults to gcNull (transparent). When set, the color is applied as an HTML background on the canvas container.

Scale

The Scale property multiplies the module width of the barcode. Increasing the scale makes the barcode physically larger while preserving the correct bar-to-space ratios required for accurate scanning.

TMSFNCWXBarcode1.Scale := 3; // Triple the bar width

DefaultSize

When DefaultSize is True, the barcode is rendered at the native size determined by the library (based on Scale). When False (the default), the component stretches the barcode to fill its Width and Height.

TMSFNCWXBarcode1.DefaultSize := True;

Human-readable text

Property Type Default Description
IncludeText Boolean True Show the encoded text below (or above) the bars
TextSize Integer 10 Font size of the human-readable text (pt)
AltText string '' Alternative text to display instead of the encoded data
HorizontalTextAlign TTMSFNCWXBarcodeTextAlign taCenter Horizontal alignment of the text
VerticalTextAlign TTMSFNCGraphicsTextAlign gtaTrailing Vertical position of the text

Horizontal text alignment values:

Value Description
taOffLeft Off to the left of the barcode
taLeft Flush left
taCenter Centered (default)
taRight Flush right
taOffRight Off to the right of the barcode
taJustify Justified

Vertical text alignment values:

Value Description
gtaTrailing Below the bars (default)
gtaCenter Centered vertically
gtaLeading Above the bars
TMSFNCWXBarcode1.IncludeText          := True;
TMSFNCWXBarcode1.AltText              := 'Product #1234';
TMSFNCWXBarcode1.TextSize             := 12;
TMSFNCWXBarcode1.HorizontalTextAlign  := taCenter;
TMSFNCWXBarcode1.VerticalTextAlign    := gtaTrailing;

Check digit

Property Type Default Description
IncludeCheck Boolean False Automatically compute and append a check digit
IncludeCheckInText Boolean False Include the computed check digit in the human-readable text

Dotty rendering

For matrix barcodes, when Dotty is True render the modules as dots rather than squares

TMSFNCWXBarcode1.Dotty := True;

Inkspread

Inkspread simulates the physical spreading of ink during printing. It is the amount by which to reduce the bar widths to compensate for inkspread, in points. Not recommended unless scale is at least 5.

Property Type Default Description
Inkspread Single 0.0 Uniform inkspread applied to all bars
HorizontalInkspread Single 0.0 Inkspread applied horizontally only
VerticalInkspread Single 0.0 Inkspread applied vertically only

Border

The BarcodeBorder property (TTMSFNCWXBarcodeBorder) adds a rectangular border around the barcode:

Property Type Default Description
Visible Boolean False Show or hide the border
Color TTMSFNCGraphicsColor gcBlack Border color
Width Single 1.0 Border line thickness (pixels)
GapLeft Integer 0 Left gap between border and barcode (pixels)
GapRight Integer 0 Right gap between border and barcode (pixels)
GapTop Integer 0 Top gap between border and barcode (pixels)
GapBottom Integer 0 Bottom gap between border and barcode (pixels)
TMSFNCWXBarcode1.BarcodeBorder.Visible    := True;
TMSFNCWXBarcode1.BarcodeBorder.Color      := gcRed;
TMSFNCWXBarcode1.BarcodeBorder.Width      := 2;
TMSFNCWXBarcode1.BarcodeBorder.GapLeft    := 5;
TMSFNCWXBarcode1.BarcodeBorder.GapRight   := 5;
TMSFNCWXBarcode1.BarcodeBorder.GapTop     := 5;
TMSFNCWXBarcode1.BarcodeBorder.GapBottom  := 5;

Type-specific settings

The Settings property (TTMSFNCWXBarcodeSettings) contains options that only apply to specific barcode symbologies. Settings that do not apply to the active BarcodeType are silently ignored.

General settings (multiple types)

Property Type Default Applicable to
Parse Boolean False Code 128, Code 16K, Code 39 Ext, Code 49, Code 93 Ext, CodablockF, Telepen, Aztec
Raw Boolean False Code 128, CodablockF, Aztec Code
Mode Integer -1 Code 16K, Code 49, MaxiCode, Han Xin, PDF417
Columns Integer -1 PDF417, MicroPDF417, CodablockF
Rows Integer -1 PDF417, CodablockF, Code 16K, Code 49
RowHeight Integer 10 CodablockF, Code 16K, Code 49
SeparatorHeight Integer 1 CodablockF, Code 16K, Code 49
ECLevel Integer -1 PDF417, MicroPDF417, Aztec Code, Han Xin
Segments Integer -1 DotCode, GS1 DotCode
GuardWhiteSpace Boolean False EAN-13, EAN-8, UPC-A, UPC-E, ISBN, ISMN, ISSN

Parse mode

When Parse is True, the text is processed as an escape-sequence string where ^NNN sequences are replaced with the character whose ASCII value is NNN. This allows embedding otherwise unprintable characters (function codes, mode-switch characters, etc.) into the barcode data.

// Embed FNC1 (ASCII 94) in a Code 128 barcode
TMSFNCWXBarcode1.Settings.Parse := True;
TMSFNCWXBarcode1.Text := '^094' + '0123456789';

Australia Post

Property Type Default Description
AusPosCustInfoEnc TTMSFNCWXBarcodeAusPostCustInfoEnc cieCharacter Encoding for the customer information field
Value Description
cieNumeric Numeric-only customer information
cieCharacter Alphanumeric customer information

Aztec Code / Aztec Code Compact

Property Type Default Description
AztecCodeECAddChars Integer 3 Number of extra error-correction codewords to add
AztecCodeLayers Integer -1 Number of layers; -1 = auto
AztecCodeReaderInit Boolean False Set the Reader Initialization flag

BC412

Property Type Default Description
BC412IncludeStartStop Boolean False Include start/stop characters in output
BC412Semi Boolean False Use semi-continuous variant

Channel Code

Property Type Default Description
ChannelCodeShortFinder Boolean False Use the short finder pattern

Codabar

Property Type Default Description
CodabarAltStartStop Boolean False Use alternate start/stop characters

Code 39

Property Type Default Description
Code39HideStars Boolean False Hide the * start/stop characters from the human-readable text

Code One

Property Type Default Description
CodeOneVersion TTMSFNCWXBarcodeCodeOneVersion covA Code One version
Value Description
covAcovH Standard versions A through H
covT16, covT32, covT48 T-series versions
covS10, covS20, covS30 S-series versions

DotCode / GS1 DotCode

Property Type Default Description
DotCodeRatio Single 1.5 Width-to-height ratio of each dot

Han Xin

Property Type Default Description
HanXinVersion Integer 1 Han Xin version (1–84)

ISBN / ISMN / ISSN

These symbologies support individual text positioning for the human-readable supplement number.

Property Type Default Description
ISBNTextSize Integer -1 ISBN supplement text size (pt); -1 = default
ISBNTextXOffset Integer -1 ISBN supplement text horizontal offset
ISBNTextYOffset Integer -1 ISBN supplement text vertical offset
ISMNTextSize Integer -1 ISMN supplement text size (pt); -1 = default
ISMNTextXOffset Integer -1 ISMN supplement text horizontal offset
ISMNTextYOffset Integer -1 ISMN supplement text vertical offset
ISSNTextSize Integer -1 ISSN supplement text size (pt); -1 = default
ISSNTextXOffset Integer -1 ISSN supplement text horizontal offset
ISSNTextYOffset Integer -1 ISSN supplement text vertical offset

Mailmark (Royal Mail)

Property Type Default Description
MailmarkType TTMSFNCWXBarcodeMailmarkType mt7 Mailmark barcode type
Value Description
mt7 7-character C-encoded
mt9 9-character L-encoded
mt29 29-character C-encoded

MSI (Modified Plessey)

Property Type Default Description
MSICheckType TTMSFNCWXBarcodeMSICheckType mctMod10 Check digit algorithm
MSIBadMod11 Boolean False Use the IBM/NCR variant of Mod 11

MSI check types:

Value Description
mctMod10 Mod 10 (Luhn)
mctMod1010 Mod 10 / Mod 10
mctMod11 Mod 11
mctNcrMod11 NCR Mod 11
mctMod1110 Mod 11 / Mod 10
NcrMod1110 NCR Mod 11 / Mod 10

PDF417

Property Type Default Description
PDF417RowMult Integer 3 Row height multiplier (ratio of row height to module width)

Plessey

Property Type Default Description
PlesseyUndricetional Boolean False Use unidirectional Plessey variant

PosiCode

Property Type Default Description
PosiCodeVersion TTMSFNCWXBarcodePosiCodeVersion pcvA PosiCode version
Value Description
pcvA PosiCode A
pcvB PosiCode B
pcvLimitedA PosiCode Limited A
pcvLimitedB PosiCode Limited B

PZN (Pharmazentralnummer)

Property Type Default Description
PZNVariant TTMSFNCWXBarcodePZNVariant pvPZN7 PZN variant
Value Description
pvPZN7 7-digit PZN
pvPZN8 8-digit PZN

Customization example

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCWXBarcode1.BarcodeBorder.Color := gcRed;
  TMSFNCWXBarcode1.BarcodeBorder.Width := 2;
  TMSFNCWXBarcode1.BarcodeBorder.Visible := True;
  TMSFNCWXBarcode1.Color := gcAliceblue;
  TMSFNCWXBarcode1.Scale := 2; //Make it bigger while maintaining correct line ratio
end;

TTMSFNCWXBarcode


Properties reference

TTMSFNCWXBarcode

Property Type Default Description
AltText string '' Alternative human-readable text; replaces encoded data in the label
AutoClearCache Boolean Clears the internal web browser cache on reinitialize
BackgroundColor TTMSFNCGraphicsColor gcNull Background color of the barcode container
BarColor TTMSFNCGraphicsColor gcBlack Color of the bars
BarcodeBorder TTMSFNCWXBarcodeBorder Border drawn around the barcode
BarcodeType TTMSFNCWXBarcodeType bciCode128 Barcode symbology
DefaultSize Boolean False Use library-native size instead of stretching to component size
Dotty Boolean False Render squares as dots
HorizontalTextAlign TTMSFNCWXBarcodeTextAlign taCenter Horizontal alignment of human-readable text
ImageFormat TTMSFNCWXBarcodeImageFormat bifPNG Output format: PNG or SVG
IncludeCheck Boolean False Auto-compute and append a check digit
IncludeCheckInText Boolean False Include check digit in the human-readable text
IncludeText Boolean True Show human-readable text
Inkspread Single 0.0 Uniform inkspread
HorizontalInkspread Single 0.0 Horizontal inkspread
VerticalInkspread Single 0.0 Vertical inkspread
LibraryLocation TTMSFNCWXLibraryLocation llOnline Load JS library online or from resources
Scale Integer 1 Bar module width multiplier
Settings TTMSFNCWXBarcodeSettings Type-specific barcode options
Text string '123456' Data to encode
TextSize Integer 10 Font size of human-readable text (pt)
VerticalTextAlign TTMSFNCGraphicsTextAlign gtaTrailing Vertical position of the human-readable text

TTMSFNCWXBarcodeBorder

Property Type Default Description
Color TTMSFNCGraphicsColor gcBlack Border line color
GapBottom Integer 0 Bottom gap between border and barcode (px)
GapLeft Integer 0 Left gap between border and barcode (px)
GapRight Integer 0 Right gap between border and barcode (px)
GapTop Integer 0 Top gap between border and barcode (px)
Visible Boolean False Show or hide the border
Width Single 1.0 Border line thickness (px)

TTMSFNCWXBarcodeSettings

Property Type Default Description
AusPosCustInfoEnc TTMSFNCWXBarcodeAusPostCustInfoEnc cieCharacter AusPost customer info encoding
AztecCodeECAddChars Integer 3 Aztec extra EC codewords
AztecCodeLayers Integer -1 Aztec layers (-1 = auto)
AztecCodeReaderInit Boolean False Aztec Reader Initialization flag
BC412IncludeStartStop Boolean False BC412 include start/stop
BC412Semi Boolean False BC412 semi-continuous variant
ChannelCodeShortFinder Boolean False Channel Code short finder pattern
CodabarAltStartStop Boolean False Codabar alternate start/stop
Code39HideStars Boolean False Hide * from Code 39 human-readable text
CodeOneVersion TTMSFNCWXBarcodeCodeOneVersion covA Code One version
Columns Integer -1 Columns for stacked/2D types (-1 = auto)
DotCodeRatio Single 1.5 DotCode dot aspect ratio
ECLevel Integer -1 Error correction level (-1 = default)
GuardWhiteSpace Boolean False Force white space around guard bars
HanXinVersion Integer 1 Han Xin version
ISBNTextSize Integer -1 ISBN supplement text size
ISBNTextXOffset Integer -1 ISBN supplement X offset
ISBNTextYOffset Integer -1 ISBN supplement Y offset
ISMNTextSize Integer -1 ISMN supplement text size
ISMNTextXOffset Integer -1 ISMN supplement X offset
ISMNTextYOffset Integer -1 ISMN supplement Y offset
ISSNTextSize Integer -1 ISSN supplement text size
ISSNTextXOffset Integer -1 ISSN supplement X offset
ISSNTextYOffset Integer -1 ISSN supplement Y offset
MailmarkType TTMSFNCWXBarcodeMailmarkType mt7 Mailmark barcode type
Mode Integer -1 Encoding mode for applicable types
MSIBadMod11 Boolean False MSI IBM/NCR Mod 11 variant
MSICheckType TTMSFNCWXBarcodeMSICheckType mctMod10 MSI check digit algorithm
Parse Boolean False Enable escape-sequence parsing in Text
PDF417RowMult Integer 3 PDF417 row height multiplier
PlesseyUndricetional Boolean False Plessey unidirectional variant
PosiCodeVersion TTMSFNCWXBarcodePosiCodeVersion pcvA PosiCode version
PZNVariant TTMSFNCWXBarcodePZNVariant pvPZN7 PZN 7- or 8-digit variant
Raw Boolean False Pass raw barcode data to the library
RowHeight Integer 10 Row height for stacked symbologies
Rows Integer -1 Number of rows for stacked/2D types (-1 = auto)
Segments Integer -1 Number of DotCode segments (-1 = auto)
SeparatorHeight Integer 1 Separator height for stacked symbologies

Methods reference

Method Description
GetBarcode(AText: string): TTMSFNCBitmap Synchronously renders and returns the barcode as a bitmap (caller must free). Not available on Android.

Events reference

Event Signature Description
OnGetBarcode procedure(Sender: TObject; ABitmap: TTMSFNCBitmap) Fired each time the barcode is rendered; provides the result as a bitmap
OnInitialized TNotifyEvent Fired once the embedded browser and JS library have finished loading

Loading modes (LibraryLocation)

Most WX components offer the option to load the JavaScript library from an online CDN or from embedded resources. Set this via the LibraryLocation property:

  • llOnline — The library is loaded live from cdn.jsdelivr.net. Fastest initial load; requires an internet connection.
  • llOffline — The library is loaded from the application's resources. Works without internet; may increase load time on low-powered devices.

When deploying your application, choose the mode that matches your target environment.


Further reading

For the full list of symbology-specific options in the underlying library, refer to the official BWIPP documentation: https://github.com/bwipp/postscriptbarcode/wiki