How To Center a Code 39 Full ASCII Barcode Using Java Script
Description
How to center a Code 39 Full ASCII barcode using a Java Script datasource. This can also be used with standard Code 39 The 3 of 9 bar code is a variable length, discrete, self-checking, bidirectional, alphanumeric bar code. Its character set contains 43 meaningful characters: 0-9, A-Z, -, ., $, /, %, *, and space. Each character is composed of nine elements: five bars and four spaces. Three of the nine elements are wide (binary value 1), and six elements are narrow (binary value 0). The character (*) is used for both start and stop character. 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.
<pre class="syntaxhighlighter-pre" xml:space="preserve">// CENTER CODE 39 Full ASCII BARCODE
//
// ((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
</pre>
Note
To modify this script so that it will work with standard Code 39, comment out lines 14 thru 16.
Article Number
2016058
Versions
Loftware Label A label is a design area on the computer screen where a label format is created or edited. Manager / Loftware Print Server versions 9.5.2.0 - 11.1
Environment
Any supported Loftware Printer Server or Label Manager Environment