Table of Content

Install & Usage

Develop

F&Q

JS API Manual

SPIRIT.open( opt, [callback, [errcb]])

Turn on the printer. This function will return the printer object instance p through the callback function, Further operations can be performed, such as printing text p.Text(...).

Object instance operation is recorded as SPIRIT#fun() in this manual, pay attention to the difference with SPIRIT.fun().

If no callback is specified, a Promise will be returned.

SPIRIT.open(opt, function(p){
    p.initLabel(80, 210);
    p.Text(0, 0, "Test Text");
    p.print();
    p.close();
})

or

SPIRIT.open(opt).then(function(p){
    p.initLabel(80, 210);
    p.Text(0, 0, "Test Text");
    p.print();
    p.close();
}).catch(function(e)=>{
    alert("Cannot connect to the print server");
})

The parameter opt is used to specify printer parameters, including: printer name, printer type, printer resolution parameters, and can override the corresponding default values. Use an empty object to use the default configuration.

Params Content   Example Remarks
name Printer name
type Printer type ZPL/CPCL/WIN
dpi Printer resolution (dots/inch) 203 dpi/dpmm two options
dpmm Printer resolution (dot/mm) 8
font Printer font MHEIGB18.TTF Not valid for windows printers
cache Whether to use template cache true Used by default. Generally, when adjusting the template, set this parameter to false

SPIRIT#PrintLabel(label/labelID, [{var1:xxx, var2:xxx, ...}, [url ]])

The first parameter can be template data or template ID, if it is template ID, the template data will be loaded from the server.

The second parameter is a variable list, which will replace the template variable with the same name when printing, which is optional.

The third parameter is the url of the download template ID, which is optional and defaults to this website. If you need to use the intranet, you can set it as the proxy URL of the intranet. See FAQ for details

SPIRIT#initLabel(w, h)

Initialize the label. w is the width of the label, and h is the height. The unit of w, h is 0.1 mm, for example, initLabel(1000,500) means a label with a width of 10 cm and a height of 5 cm, the same below.

SPIRIT#Font(font, hsize, wsize, rotate)

Set the print font. The settings will be saved until the next SPIRIT#Font is called.

-font is the name of the font. Note that it must be the printer's built-in font. Please check the printed manual. -hsize is the height of the text, the unit is 0.1 mm. -wsize is the width of the text, the default is hsize -rotate is the text direction, support: 0-no rotation. 1- Rotate 90 degrees. 2- Rotate 180 degrees. 3- Rotate 270 degrees.

SPIRIT#Text(x, y, text)

Start printing text at the (x,y) coordinates of the label.

SPIRIT#TextEx(x, y, text, hszie, [wsize, [rotate, [font]])

Set the font first, and then start printing text at the (x,y) coordinates of the label. The parameter meaning is the same as SPIRIT#Font(), but note that the order is different. The purpose of this is to omit some parameters if you only need to change the size and direction of rotation.

Note: SPIRIT#TexEx() changes the font to temporary, the next SPIRIT#Text is invalid.

SPIRIT#Line( sx, sy, ex, ey, l)

Draw a line with width l from (sx,sy) to (ex,ey).

SPIRIT#Rect( x, y, w, h, l)

Draw a wireframe with the upper left corner (x, y), width w, height h, and line width l.

SPIRIT#Barcode1D(x, y, codeType, roate, content, height, p, nw, ww)

Start printing a 1D barcode at the (x,y) coordinates of the label. The meaning of other parameters is:

-codeType barcode type, currently supports: Code128, Code39, Code93, CodeEAN8, CodeEAN13, CODABAR, ITF25, UPCA, UPCE -rotate to rotate the barcode. 0-Do not rotate. 1- Rotate 90 degrees. 2- Rotate 180 degrees. 3- Rotate 270 degrees. -content Barcode content -p content text position -nw barcode width -ww barcode wide line width

  p.Barcode1D(0, 100, "Code128", 0, `1234569890123`, 80, "AlignCenter", 4, 10);

SPIRIT#print()

Perform printing. To print a label, you must start with SPIRIT#initLabel() and end with SPIRIT#print.

SPIRIT#printRaw(str)

Send commands directly to the printer.

SPIRIT#hasError()

Check for errors.

SPIRIT#getErrors()

Get a list of errors

SPIRIT.open(opt, function(p){
    p.initLabel(80, 210);
    ...
    if (p.hasError()) {
        alert(p.getErrors.join("\n"));
    }
    p.close();
})

SPIRIT#close()

Close the printer connection and release resources.


Leave Your Message

login