Skip to end of metadata
Go to start of metadata


How to center a Code 39 Full ASCII barcode using a Java Script datasource. This can also be used with standard Code 39 with a minor modification.

How to Center a Code 39 Full ASCII Barcode using Java Script

Use the following Script, but replace 'CODE39' with the name of your data input field.

A Line field with the Line Length property set to the width of the label must be added to the label template . This Line field can be a non-printing element (Printing Field property set to No) and its Field Name must be set to BAR_WIDTH.
// ((16*(#CHAR+2))-)*xdim = length in 1/1000"
// standard Code 39 Characters [A-Z][0-9]-.[SPACE]
// collect the necessary information

var xdim=String(label.fields.field.(@name == 'CODE39').barcode.@barLineXDim); // width of individual line elements in 1/1000 inch 
var barcodeData = String(label.fields.field.(@name == 'CODE39').@data); // input data 
var barcodeLength= Number(barcodeData.length); // raw number of characters to encode 
var labelWidth=Number(label.fields.field.(@name == 'BAR_WIDTH').@lineLength); // length of a line running the width of the label 
var actualLength = barcodeLength;

barcodeData = barcodeData.replace(/[A-Z]|[0-9]|[ .-]/g,""); //remove all characters that require only one encoded character
var FullASCIILength=Number(barcodeData.length); // number of characters requiring 2 encoded characters 
actualLength = Number(FullASCIILength + actualLength); // number of total encoded characters

actualLength = Number((xdim*((16*(actualLength+2))-1))/1000); // width of resulting barcode 
var newStartPoint = Number((labelWidth-actualLength)/2); // compute new left position 
newStartPoint = Math.round(newStartPoint*Math.pow(10,2))/Math.pow(10,2); // round result to the nearest 1/100th inch

label.fields.field.(@name =='CODE39').@posLeft= newStartPoint; // move barcode



To modify this script so that it will work with standard Code 39, comment out lines 14 thru 16.

Article Number



Loftware Version 9.5.3 and up


Any supported Loftware Printer Server or Label Manager Environment