Epson POS printers Programming Guide
The Epson POS printers are designed for printing receipts and other documents in retail environments. They offer a variety of features, including high-speed printing, easy-to-use interface, and support for multiple paper types. These printers are compatible with a variety of POS systems and can be used for a wide range of applications, including retail sales, restaurants, and hospitality.
Advertisement
Advertisement
Chapter 3 Programming Guide
Programming Guide
This chapter describes how to write programs in the application development using ePOS-Print.
ePOS-Print Canvas API ( p. 43
)
ePOS-Print API
Print Mode
There are two types of print modes: standard and page modes.
Standard mode
In standard mode, characters are printed line by line. The line feed space is adjusted based on the font size and the height of images, barcodes, etc. This mode is suitable for the type of printing such as printing receipts that requires the paper length to change according to the print space.
Page mode
In page mode, you set a print area, lay out data in it, and print the data in a batch operation. Characters, images, and barcodes are laid out in the print positions (coordinates).
3
33
34
Programming Flow
For the ePOS-Print API, programming is performed based on the following work flow:
Embedding of ePOS-Print SDK for JavaScript (p.35)
Print Document Creation (p.36)
❏
To create a text print document: (p.37)
❏
To create a graphic print document: (p.37)
❏
To create a page mode print document (p.38)
Transmission of Print Document (p.39)
Reception of Print Result (p.40)
• ePOS-Print supported TM printer checks the status of the TM printer to be used for printing and then starts printing operation.
• A status event helps check the status of the TM printer. For details on the procedure, refer to
Reception of Status Event ( p. 42
).
Chapter 3 Programming Guide
Embedding of ePOS-Print SDK for JavaScript
This describes embedding of ePOS-Print SDK for JavaScript. The file name is "epos-print-x.x.x.js."
Preparation
To use the ePOS-Print API, place epos-print-x.x.x.js on the Web server.
Embedding into Web pages
Embed the script into the Web page by using the HTML <script> tags.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Embed
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
var builder = new epson.ePOSBuilder();
.
.
}
</script>
</head>
<body>
.
.
</body>
</html>
3
35
36
Print Document Creation
A print document is created using an ePOS-Print Builder object.
Create an ePOS-Print Builder object using the constructor for it; create a print document using the object's
Refer to the following program for print document creation.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create an ePOS-Print Builder object
var builder = new epson.ePOSBuilder();
//Create a print document
builder.addTextLang('en')
builder.addTextSmooth(true);
builder.addTextFont(builder.FONT_A);
builder.addTextSize(3, 3);
builder.addText('Hello,\tWorld!\n');
Create a print document
builder.addCut(builder.CUT_FEED);
//Acquire the print document
var request = builder.toString();
alert(request);
}
</script>
</head>
<body>
<button onclick=”buildMessage()”>Run</button>
</body>
</html>
Chapter 3 Programming Guide
To create a text print document:
To create a text print document, store the font settings into the command buffer using text methods and then create a print document. Refer to the following program.
For the string "Hello World!", to create a print document based on the following settings:
❏ Font:
❏ Scale:
❏ Style:
FontA x 4 (horizontal) and x 4 (vertical)
Bold
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create an ePOS-Print Builder object
var builder = new epson.ePOSBuilder();
//Create a print document
//<Configure the print character settings>
builder.addTextLang('en');
builder.addTextSmooth(true);
builder.addTextFont(builder.FONT_A);
builder.addTextSize(4, 4);
builder.addTextStyle(false, false, true, undefined);
//<Specify the print data>
builder.addText('Hello,\tWorld!\n');
builder.addCut(builder.CUT_FEED);
//Acquire the print document
var request = builder.toString();
}
</script>
To create a graphic print document:
To create a graphic print document, store a raster image obtained by rendering an image in HTML5
Canvas into the command buffer using the addImage method. Refer to the following program.
To create a print document for the image file “logo.bmp”
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create an ePOS-Print Builder object
var builder = new epson.ePOSBuilder();
//Render an image in HTML5 Canvas
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.drawImage(document.getElementById('logo'), 0, 0, 200, 70);
//Create a print document
builder.addTextAlign(builder.ALIGN_CENTER);
builder.addImage(context, 0, 0, canvas.width, canvas.height, builder.COLOR_1);
builder.addCut(builder.CUT_FEED);
//Acquire the print document
var request = builder.toString();
}
</script>
This section describes how to print a raster image. In addition, there is also a method of printing
graphics registered in the NV memory of the printer. For details, refer to addLogo method (p.77)
.
3
37
38
To create a page mode print document
When the addPageBegin method is stored in the command buffer, the page mode starts. Store the print area (addPageArea method) and the print start position (addPagePosition method) into the command buffer. Specify the print start position according to the print data. After that, store the methods into the command buffer to create print data. For the end of page mode, store the addPageEnd method into the command buffer.
For the string "Hello World!", to create a print document based on the following settings:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create an ePOS-Print Builder object
var builder = new epson.ePOSBuilder();
//Create a print document
//<The page mode starts>
builder.addPageBegin();
//<Specify the page mode print area>
builder.addPageArea(100, 50, 200, 100);
//<Specify the page mode print position>
builder.addPagePosition(0, 42);
//<Specify the print data>
builder.addTextLang('en');
builder.addTextFont(builder.FONT_A);
builder.addTextSize(4, 4);
builder.addTextStyle(false, false, true, undefined);
builder.addText('Hello,\tWorld!\n');
//<The page mode ends>
builder.addPageEnd();
builder.addCut(builder.CUT_FEED);
//Acquire the print document
var request = builder.toString();
}
</script>
Chapter 3 Programming Guide
Transmission of Print Document
A print document is sent using an ePOS-Print object.
Create an ePOS-Print object using the constructor and specify the end point address for the printer to be used for printing as well as the print document into the send method to send the document.
For the details about the printer end point address, refer to
Printer End Point Address (p.39)
.
Refer to the following program.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create a print document
var builder = new epson.ePOSBuilder();
builder.addTextLang('en');
builder.addTextSmooth(true);
builder.addTextFont(builder.FONT_A);
builder.addTextSize(3, 3);
builder.addText('Hello,\tWorld!\n');
builder.addCut(builder.CUT_FEED);
var request = builder.toString();
Transmission of print document
//Set the end point address
var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer&timeout=10000';
//Create an ePOS-Print object
var epos = new epson.ePOSPrint(address);
//Send the print document
epos.send(request);
}
</script>
</head>
<body>
<button onclick=”buildMessage()”>Run</button>
</body>
</html>
Printer End Point Address
Specify the printer end point address in the following format: http://[domain]/cgi-bin/epos/service.cgi?devid=[device ID]&timeout=[timeout time]
Items to specify
Domain
Device ID
Timeout period
Description
Specify IP address or domain of TM printer.
Specifies the TM printer to be used for printing.
Specify device ID of TM printer.
Specifies the time to abort the process in milliseconds.
The maximum value is 300 seconds (3000000).
The timeout parameter is optional; when it is omitted, 60 seconds (60000) is set.
When the timeout period elapses, the print job is canceled; the data already interpreted by the printer before the start of the print abort process is printed.
3
39
40
Reception of Print Result
The print result can be received by setting a callback function using the onreceive property (
ePOS-Print object. The following information is obtained:
❏ Print result
❏ Error code
❏ Printer status
The printer status can be obtained when communication with the printer is possible.
Refer to the following program. For the details about how to program a callback function in detail, refer to
.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function buildMessage() {
//Create a print document
var builder = new epson.ePOSBuilder();
builder.addTextLang('en');
builder.addTextSmooth(true);
builder.addTextFont(builder.FONT_A);
builder.addTextSize(3, 3);
builder.addText('Hello,\tWorld!\n');
builder.addCut(builder.CUT_FEED);
var request = builder.toString();
var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer&timeout=10000';
//Create an ePOS-Print object
var epos = new epson.ePOSPrint(address);
//Set a response receipt callback function
epos.onreceive = function (res) {
//When the printing is not successful, display a message
if (!res.success) {
alert('A print error occurred');
}
}
//Send the print document
epos.send(request);
}
</script>
</head>
<body>
<button onclick=”buildMessage()”>Run</button>
</body>
</html>
Print result receipt callback function
Chapter 3 Programming Guide
Error handling
Refer to the following program for the error handling method by a callback function.
//Create an ePOS-Print object var epos = new epson.ePOSPrint(address);
// Set a response receipt callback function epos.onreceive = function (res) {
// Obtain the print result and error code
var msg = 'Print' + (res.success ? 'Success' : 'Failure') + '\ nCode:
' + res.code
+ '\ nStatus:
\n';
// Obtain the printer status
var asb = res.status;
if (asb & epos.ASB_NO_RESPONSE) {
msg += ' No printer response\n';
}
if (asb & epos.ASB_PRINT_SUCCESS) {
msg += ' Print complete\n';
}
if (asb & epos.ASB_DRAWER_KICK) {
msg += ' Status of the drawer kick number 3 connector pin = "H"\n';
}
if (asb & epos.ASB_OFF_LINE) {
msg += ' Offline status\n';
}
if (asb & epos.ASB_COVER_OPEN) {
msg += ' Cover is open\n';
}
if (asb & epos.ASB_PAPER_FEED) {
msg += ' Paper feed switch is feeding paper\n';
}
if (asb & epos.ASB_WAIT_ON_LINE) {
msg += ' Waiting for online recovery\n';
}
if (asb & epos.ASB_PANEL_SWITCH) {
msg += ' Panel switch is ON\n';
}
if (asb & epos.ASB_MECHANICAL_ERR) {
msg += ' Mechanical error generated\n';
}
if (asb & epos.ASB_AUTOCUTTER_ERR) {
msg += ' Auto cutter error generated\n';
}
if (asb & epos.ASB_UNRECOVER_ERR) {
msg += ' Unrecoverable error generated\n';
}
if (asb & epos.ASB_AUTORECOVER_ERR) {
msg += ' Auto recovery error generated\n';
}
if (asb & epos.ASB_RECEIPT_NEAR_END) {
msg += ' No paper in the roll paper near end detector\n';
}
if (asb & epos.ASB_RECEIPT_END) {
msg += ' No paper in the roll paper end detector\n';
}
if (asb & epos.ASB_BUZZER) {
msg += ' Sounding the buzzer (limited model)\n';
}
if (asb & epos.ASB_SPOOLER_IS_STOPPED) {
msg += ' Stop the spooler\n';
}
//Display in the dialog box
alert(msg);
}
3
41
42
Reception of Status Event
The status event notification function is used to check the printer status without printing.
Refer to the following:
//Set the end point address var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer
&timeout=10000';
//Create an ePOS-Print Builder object var builder = new epson.ePOSBuilder(address);
//Set an event callback function (cover open) epos.oncoveropen = function () {
alert('coveropen');
};
//Set an event callback function (paper near end) epos.onpapernearend = function () {
alert('papernearend');
};
//Enable status event operation epos.open();
Chapter 3 Programming Guide
ePOS-Print Canvas API
For the ePOS-Print Canvas API, programming is performed based on the following work flow:
Embedding of ePOS-Print Canvas API (p.43)
Rendering in HTML5 Canvas (p.44)
Reception of Print Result (p.46)
A status event helps check the status of the TM printer. For details on the procedure, refer to
Reception of Status Event ( p. 42
).
Embedding of ePOS-Print Canvas API
The ePOS-Print Canvas API is provided as JavaScript. And its file name is "epos-print-x.x.x.js".
It is used by embedding epos-print-x.x.x.js into applications.
Preparation
To use the ePOS-Print Canvas API, place epos-print-x.x.x.js on the Web server.
Embedding into Web pages
Embed the script into the Web page by using the HTML <script> tags.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Embed
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function drawCanvas() {
.
.
}
</script>
</head>
<body>
.
.
</body>
</html>
43
3
44
Rendering in HTML5 Canvas
Render an image in HTML5 Canvas.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Rendering in HTML5 Canvas
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function drawCanvas() {
// Rendering in HTML5 Canvas
//<Obtain the context>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
//<Render an image>
context.clearRect(0, 0, 512, 480);
context.drawImage(document.getElementById('coffee'), 0, 0
, 512, 384);
context.fillStyle = 'rgba(255, 255, 255, 0.5)';
context.fillRect(0, 0, 512, 480);
context.fillStyle = 'rgba(0, 0, 0, 1.0)';
//<Render a water mark for the image>
context.drawImage(document.getElementById('wmark'), 0, 0);
context.drawImage(document.getElementById('wmark'), 256, 324);
//<Render text>
context.textAlign = 'center';
context.textBaseline = 'alphabetic';
context.font = 'bold normal normal 48px "Times New Roman", serif';
context.fillText('FREE Coffee', 256, 224);
}
</script>
</head>
<body>
<button onclick="drawCanvas()">Run</button>
<canvas id="myCanvas" width="512" height="480"></canvas>
<img id="coffee" src="img/coffee.jpg" alt="">
<img id="wmark" src="img/wmark.png" alt="">
</body>
</html>
Chapter 3 Programming Guide
Prints an Canvas image
Content drawn in HTML5 Canvas is printed using the ePOS-Print Canvas API.
Create an ePOS-Print Canvas API object using the constructor; for the Print method, specify the end point address for the printer to be used for printing as well as the canvas content and whether to select paper
Refer to the following program.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function drawCanvas() {
// Rendering in HTML5 Canvas
//<Obtain the context>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
.
.
.
Transmission of print document
//Set the end point address
var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer&timeout=10000';
//Create an ePOS-Print Canvas API object
var epos = new epson.CanvasPrint(address);
epos.cut = true;
epos.print(canvas);
}
</script>
</head>
<body>
<button onclick="drawCanvas()">Run</button>
<canvas id="myCanvas" width="512" height="480"></canvas>
<img id="coffee" src="img/coffee.jpg" alt="">
<img id="wmark" src="img/wmark.png" alt="">
</body>
</html>
For the details about the printer end point address, refer to Printer End Point Address (p.39)
.
3
45
46
Reception of Print Result
The print result can be received by setting a callback function using the onreceive property (
ePOS-Print Canvas API object. The following information is obtained:
❏ Print result
❏ Error code
❏ Printer Status
The printer status can be obtained when communication with the printer is possible.
Refer to the following program. For the details about how to program a callback function in detail, refer to
.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TITLE</title>
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
function drawCanvas() {
// Rendering in HTML5 Canvas
//<Obtain the context>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
.
.
.
//Set the end point address
var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer&timeout=10000';
//Create an ePOS-Print Canvas API object
var epos = new epson.CanvasPrint(address);
//Set a response receipt callback function
epos.onreceive = function (res) {
//When the printing is not successful, display a message
if (!res.success) {
alert('A print error occurred');
}
}
epos.cut = true;
epos.print(canvas);
}
</script>
</head>
<body>
<button onclick="drawCanvas()">Run</button>
Print result receipt callback function
<canvas id="myCanvas" width="512" height="480"></canvas>
<img id="coffee" src="img/coffee.jpg" alt="">
<img id="wmark" src="img/wmark.png" alt="">
</body>
</html>
Chapter 3 Programming Guide
Error handling
Refer to the following program for the error handling method by a callback function.
var epos = new epson.CanvasPrint(address);
// Set a response receipt callback function epos.onreceive = function (res) {
// Obtain the print result and error code
var msg = ''Print ' + (res.success ? 'Success' : 'Failure') + '\n
Code:
'
+ res.code + '\nStatus
:
\n';
// Obtain the printer status
var asb = res.status;
if (asb & epos.ASB_NO_RESPONSE) {
msg += ' No printer response\n';
}
if (asb & epos.ASB_PRINT_SUCCESS) {
msg += ' Print complete\n';
}
if (asb & epos.ASB_DRAWER_KICK) {
msg += ' Status of the drawer kick number 3 connector pin = "H"\n';
}
if (asb & epos.ASB_OFF_LINE) {
msg += ' Offline status\n';
}
if (asb & epos.ASB_COVER_OPEN) {
msg += ' Cover is open\n';
}
if (asb & epos.ASB_PAPER_FEED) {
msg += ' Paper feed switch is feeding paper\n';
}
if (asb & epos.ASB_WAIT_ON_LINE) {
msg += ' Waiting for online recovery\n';
}
if (asb & epos.ASB_PANEL_SWITCH) {
msg += ' Panel switch is ON\n';
}
if (asb & epos.ASB_MECHANICAL_ERR) {
msg += ' Mechanical error generated\n';
}
if (asb & epos.ASB_AUTOCUTTER_ERR) {
msg += ' Auto cutter error generated\n';
}
if (asb & epos.ASB_UNRECOVER_ERR) {
msg += ' Unrecoverable error generated\n';
}
if (asb & epos.ASB_AUTORECOVER_ERR) {
msg += ' Auto recovery error generated\n';
}
if (asb & epos.ASB_RECEIPT_NEAR_END) {
msg += ' No paper in the roll paper near end detector\n';
}
if (asb & epos.ASB_RECEIPT_END) {
msg += ' No paper in the roll paper end detector\n';
}
if (asb & epos.ASB_BUZZER) {
msg += ' Sounding the buzzer (limited model)\n';
}
if (asb & epos.ASB_SPOOLER_IS_STOPPED) {
msg += ' Stop the spooler\n';
}
//Display in the dialog box
alert(msg);
}
3
47
48
Reception of Status Event
The status event notification function is used to check the printer status without printing.
Refer to the following.
//Set the end point address var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer
&timeout=10000';
//Create an ePOS-Print Canvas API object var epos = new epson.CanvasPrint(address);
//Set an event callback function (cover open) epos.oncoveropen = function () {
alert('coveropen');
};
//Set an event callback function (paper near end) epos.onpapernearend = function () {
alert('papernearend');
};
//Enable status event operation epos.open();
Chapter 3 Programming Guide
Specifying the Print Job ID from the Application
A response containing the specified print job ID will be returned when sending a request from the application by specifying the print job ID. (ePOS-Print Service Ver.4.1 or later versions)
Job ID : ABC123
Print data
Job ID : ABC123
Response data
Programming Example
var printjobid = 'ABC123';
var builder = new epson.ePOSBuilder(); builder.addText('Hello, World!\n'); builder.addCut(); var request = builder.toString(); var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer’; var epos = new epson.ePOSPrint(address); epos.onreceive = function (res) { alert(res.printjobid); }; epos.onerror = function (err) { alert(err.status); };
epos.send(request, printjobid);
3
49
50
Chapter 4 API Reference
API Reference
This chapter describes the ePOS-Print API.
Concerning ePOS-Print Canvas API, see
Canvas API Reference (p.143) .
List of API functions
ePOS-Print provides the following objects:
❏ ePOS-Print Builder (window.epson.ePOSBuilder) Object ( p. 51
)
❏ ePOS-Print (window.epson.ePOSPrint) Object (
)
window.epson.ePOSBuilder Components
● : Available, - : Not available
API Description
Constructor ePOS Builder
Method
Text
Paper
Feed
Initializes an ePOS-Print XML Builder object
● ●
addTextAlign addText
Adds a tag for the text alignment setting.
Adds a tag for printing text.
●
-
addTextLineSpace Adds a tag for the line feed space setting.
● ●
addTextRotate Adds a tag for the text rotation setting.
●
-
● ●
addTextLang
Adds a tag for the target language setting.
● ●
addTextFont addTextSmooth
Adds a tag for the text font setting.
Adds a tag for the text smoothing setting.
● ●
● ●
addTextDouble
Adds a tag for specifying the double-sized text setting.
● ●
addTextSize addTextStyle
Adds a tag for the text scale setting.
Adds a tag for the text style setting.
● ●
● ●
addTextPosition
Adds a tag for specifying the print position of text.
● ●
addTextVPosition
Adds a tag for specifying the print vertical position of text.
-
●
addFeedUnit addFeedLine
Adds a tag for paper feeding (in dots).
Adds a tag for paper feeding (in lines).
● ●
● ●
addFeedPosition
Adds control of label paper/black mark paper to command buffer
●
-
addFeed Adds a line feed to the command buffer.
●
-
51
4
52
● : Available, - : Not available
API Description
Method
Graphic
Barcode
Ruled line addImage addLogo addBarcode addSymbol addHLine addVLineBegin addVLineEnd addPageBegin addPageEnd
Pagemode addPageArea
Page mode
Cut
Drawer
kick-out
Buzzer
Layout
Recovery
Reset
Send
Command
Create
a Print
Document addPageDirection addPagePosition addPageLine addPageRectangle addCut addPulse addSound addLayout addRecovery addReset addCommand toString
Adds a tag for a raster image to be printed.
Adds a tag for an NV logo to be printed.
Adds a tag for a barcode to be printed.
Adds a tag for a 2D-code to be printed.
Adds a tag for a horizontal line to be printed.
Adds a tag for starting a vertical line.
Adds a tag for finishing a vertical line.
Adds a tag for switching to page mode.
Adds a tag for finishing page mode.
Adds a tag for specifying the print area in page mode.
Adds a tag for specifying the print direction in page mode.
Adds a tag for specifying the print position in page mode.
Adds a tag for drawing a line in page mode.
Adds a tag for drawing a rectangle in page mode.
Adds a tag for paper cut.
Adds a tag for the drawer kick-out.
Adds a tag for turning on the buzzer.
Adds the paper layout setup to command buffer
Adds a tag for recovering from an error.
Adds a tag for resetting the printer.
Adds commands to the command buffer.
Sends ESC/POS commands.
Obtains a print document generated by on ePOS-Print Builder object.
● ●
● ●
● ●
● ●
●
-
●
-
●
-
●
-
●
-
-
●
-
-
-
●
●
●
-
●
-
●
●
-
●
-
●
-
●
-
●
-
● ●
●
-
Chapter 4 API Reference
Element
Property
API Description Page
halftone brightness force message
Raster image halftone processing method
Raster image brightness correction value
Forced transmission mode
Message buffer
Constant
FONT_*
ALIGN_*
COLOR_*
HALFTONE_*
MODE_*
BARCODE_*
HRI_*
SYMBOL_*
LEVEL_*
LINE_*
DIRECTION_*
CUT_*
DRAWER_*
PULSE_* font alignment color specification
Halftone type
Color mode
Barcode type
HRI position
2D-code type error correction level line style page mode print direction paper cut type drawer kick-out connector drawer kick-out pulse length
Constant
PATTERN_*
FEED_*
LAYOUT_* buzzer sound pattern
Paper feed position of label paper/black mark paper
Type of papers
Numerical values to be set to parameters
In the ePOS-Print Builder object API, numerical values are set to some parameters. Set values with the following in mind:
❏ Unit
Specify numbers in dots for units that represent length.
(Print position, paper feed space, width and height of images and barcodes, etc.)
❏ Range
Depending on the printer specifications, a specifiable range is predetermined.
For details, refer to Printer specifications (p.183) .
❏ Resolution
The resolution varies depending on the printer. It affects the actual print size. The higher the resolution is, the smaller the print size becomes, and vice versa.
For each printer's resolution, refer to Printer specifications (p.183) .
4
53
54 window.epson.ePOSPrint Components
Element
Constructor ePOS-Print
Method send open close
Property address enabled interval status battery timeout
API
drawerOpenLevel
Event onreceive onerror onstatuschange onbatterystatuschange ononline onoffline onpoweroff oncoverok oncoveropen onpaperok onpapernearend onpaperend ondrawerclosed ondraweropen onbatteryok onbatterylow
Constant
ASB_*
DRAWER_OPEN_LEVEL_*
Description Page
Initializes an ePOS-Print object
Sends a message
Enables status event operation
Disables status event operation
URL of the printer
Enabling/disabling of status event
Printer status update interval
Status
Battery status
The connecting was timeout.
Signal line status of the drawer that generates ondraweropen and ondrawerclosed events.
Response message receipt event
Communication error event
Status change event
Battery status change event
Online event
Offline event
Non-response event
Cover close event
Cover open event
Paper remaining event
Paper near end event
Paper end event
Drawer close event
Drawer open event
Battery OK event
Battery low event
Status
Signal line status to indicate that the drawer is open
Chapter 4 API Reference
ePOS-Print Builder Object
This objects creates a print document for printer control commands that specify strings or graphics to be printed, paper cut, etc.
Constructor
Constructor for an ePOS-Print Builder object.
Creates a new ePOS-Print Builder object and initializes it.
Syntax ePOSBuilder
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
}
//-->
</script>
4
55
56 addTextAlign method
Adds the text alignment setting to the command buffer.
• This API setting is applied to raster image/NV logo/barcode/2D-code.
• When using the standard mode, specify addTextAlign in "Position at the beginning of lines".
• In the page mode, addTextAlign method specification cannot be used.
In the page mode, use the addTextPosition method to designate the horizontal print position.
When the page mode is selected for the print mode, to set text rotation, use the addPageDirection
) instead of this API function.
Syntax addTextAlign
(align);
Parameter
align :
( Required parameter, Object type : String)
Specifies the text alignment.
Constant(align)
ALIGN_LEFT (default)
ALIGN_CENTER
ALIGN_RIGHT
Description
Alignment to the left
Alignment to the center
Alignment to the right
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To set alignment to the center:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextAlign(builder.ALIGN_CENTER);
}
//-->
</script>
Chapter 4 API Reference
addTextLineSpace method
Adds the line feed space setting to the command buffer.
Syntax addTextLineSpace
(linespc);
Parameter
linespc :
( Required parameter, Object type : Number)
Specifies the line feed space (in dots). Specifies an integer from 0 to 255.
Return value
ePOS-Print Builder Object
Exception
Return value
Exception
Parameter " ... " is invalid
Object type
ePOS Builder
Error
Object type
Example
To set the line feed space to 30 dots:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextLineSpace(30);
}
//-->
</script>
4
57
58 addTextRotate method
Adds the text rotation setting to the command buffer.
• This API setting also applies to barcodes/2D-codes.
• When using the standard mode, specify addTextAlign in "Position at the beginning of lines".
• In the page mode, addTextAlign method specification cannot be used.
When the page mode is selected for the print mode, to set text rotation, use the
addPageDirection method (p.98) instead of this API function.
Syntax addTextRotate
(rotate);
Parameter
rotate :
( Required parameter, Object type : Boolean)
Specifies whether to rotate text.
Setting
true or 11 false or 0 (default)
Description
Specifies rotated printing of text.
Cancels rotated printing of text.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To set text rotation:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextRotate(true);
}
//-->
</script>
Chapter 4 API Reference
addText method
Adds the printing of text to the command buffer.
After printing text, to print content other than text, execute line feed or paper feed.
In page mode, characters are laid out in the current print position with the reference point being the character baseline dot ( Printer specifications (p.183) .
Syntax addText
(data);
Parameter
data :
( Required parameter, Object type : String)
Specify a character string to be printed.
For the horizontal tab/line feed, use the following escape sequences:
String
\t
\n
\\
Description
Horizontal tab
(HT)
Line feed
(LF)
Carriage return
Return valueReturn value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To add character strings:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addText('Hello,\t').addText('World\n');
}
//-->
</script>
4
59
60 addTextLang method
Adds the language setting to the command buffer.
Syntax addTextLang
(lang);
Parameter
lang :
( Required parameter, Object type : String)
Specifies the target language.
Setting Language
en(default) de fr it es ja ja-jp ko ko-kr zh-hans zh-cn
English(ANK)
German (ANK)
French (ANK)
Italian (ANK)
Spanish (ANK)
Japanese
(International character set changes to Japan.)
Japanese
(International character set changes to Japan.)
Korean
(International character set changes to Korean.)
Korean
(International character set changes to Korean.)
Simplified Chinese
(International character set changes to China.)
Simplified Chinese
(International character set changes to China.) zh-hant zh-tw
Traditional Chinese
Traditional Chinese
Language code besides above English(ANK)
Characters not installed in a printer cannot be printed.
For printable character code, refer to the Technical Reference Guide of your printer.
Depending on language specification, a part of characters is printed as follows.
Language
Japanese
Korean
Simplified Chinese
Traditional Chinese
$
$
¥
$
Characters $(U+0024)
\
\
¥
Characters \(U+005C)
₩
Chapter 4 API Reference
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Example
To set the language as English:
Exception
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextLang('en');
}
//-->
</script>
To set the language as Korean:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextLang('ko');
}
//-->
</script>
To set the language as Simplified Chinese:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextLang('zh-hans');
}
//-->
</script>
To set the language as Traditional Chinese:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextLang('zh-hant');
}
//-->
</script>
4
61
62 addTextFont method
Adds the text font setting to the command buffer.
Syntax addTextFont
(font);
Parameter
font :
( Required parameter, Object type : String)
Specifies the font.
Constant (font)
FONT_A (default)
FONT_B
FONT_C
FONT_D
FONT_E
Font A
Font B
Font C
Font D
Font E
Language
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To set the font B:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextFont(builder.FONT_B);
}
//-->
</script>
Chapter 4 API Reference
addTextSmooth method
Adds the smoothing setting to the command buffer.
Syntax addTextSmooth
(smooth);
Parameter
smooth :
( Required parameter, Object type : Boolean)
Specifies whether to enable smoothing.
Setting
true or 1 false or 0 (default)
Description
Specifies smoothing.
Cancels smoothing
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To enable smoothing:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextSmooth(true);
}
//-->
</script>
4
63
64 addTextDouble method
Adds the double-sized text setting to the command buffer.
Syntax addTextDouble
(dw, dh);
Parameter
dw :
( Optional parameter, Object type : Boolean)
Specifies the double‐sized width.
Setting
true or 1 false or 0 (default) undefined
(When not specified)
Description
Specifies the double-sized width.
Cancels the double-sized width
Retains the current setting for double-sized width.
dh :
( Optional parameter, Object type : Boolean)
Specifies the double‐sized height.
Setting
true or 1 false or 0 (default) undefined
(When not specified)
Description
Specifies the double-sized height
Cancels the double-sized height
Retains the current setting for double-sized height
When true or 1 is set for both the dw and dh parameters, double width and height characters are printed.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Example
To set the size as double width and height:
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextDouble(true, true);
}
//-->
</script>
Chapter 4 API Reference
addTextSize method
Adds the text scale setting to the command buffer.
Syntax addTextSize
(width, height);
Parameter
width :
( Optional parameter, Object type : Number)
Specifies the horizontal scale of text.
Setting
Integer from 1 to 8 undefined
(When not specified)
Description
Horizontal scale (default : 1)
Retains the current setting for the horizontal scale.
height :
( Optional parameter, Object type : Number)
Specifies the vertical scale of text.
Setting
Integer from 1 to 8 undefined
(When not specified)
Description
Vertical scale (default : 1)
Retains the current setting for the vertical scale.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To set a horizontal scale of x 4 and a vertical scale of x 4:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextSize(4, 4);
}
//-->
</script>
4
65
66 addTextStyle method
Adds the text style setting to the command buffer.
Syntax addTextStyle
(reverse, ul, em, color);
Parameter
reverse :
( Optional parameter, Object type : Boolean)
Specifies inversion of black and white for text.
Setting
true or 1 false or 0 (default) undefined
(When not specified)
Description
Specifies the inversion of black and white parts of characters.
Cancels the inversion of black and white parts of characters.
Retains the current setting for inversion of black and white.
ul :
( Optional parameter, Object type : Boolean)
Specifies the underline style.
Setting
true or 1 false or 0 (default) undefined
(When not specified)
Description
Specifies underlining.
Cancels underlining.
Retains the current underlining setting.
em :
( Optional parameter, Object type : Boolean)
Specifies the bold style.
Setting
true or 1 false or 0 (default) undefined
(When not specified)
Description
Specifies emphasized printing of characters.
Cancels emphasized printing of characters.
Retains the current setting for emphasized printing.
color :
( Optional parameter, Object type : String)
Specifies the color.
Setting
COLOR_NONE
COLOR_1 (default)
COLOR_2
COLOR_3
COLOR_4 undefined
(When not specified)
Description
Characters are not printed.
First color
Second color
Third color
Fourth color
Retains the current color setting
Chapter 4 API Reference
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Example
To set the underline style:
Exception
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextStyle(undefined, true);
}
//-->
</script>
4
67
68 addTextPosition method
Adds the horizontal print start position of text to the command buffer.
Syntax addTextPosition
(x);
Parameter
x :
( Required parameter, Object type : Number)
Specifies the horizontal print start position (in dots).
Specifies an integer from 0 to 65535.
Return value
Return value
ePOS-Print Builder Object
Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To set the print position at 120 dots from the left end:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addTextPosition(120);
}
//-->
</script>
Chapter 4 API Reference
addTextVPosition method
Adds the vertical print start position of text to the command buffer.
Use this API function by inserting it between addPageBegin to addPageEnd.
Syntax addTextVPosition
(y);
Parameter
y :
( Required parameter, Object type : Number)
Specifies the vertical print start position (in dots).
Specifies an integer from 0 to 65535.
Return value
Return value
ePOS-Print Builder Object
Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Example
To set the print position at 120 dots from the top:
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addTextVPosition(120);
builder.addPageEnd();
}
//-->
</script>
4
69
70 addFeedUnit method
Adds paper feeding in dots to the command buffer.
Syntax addFeedUnit
(unit);
Parameter
unit :
( Required parameter, Object type : Number)
Specifies the paper feed space (in dots). Specifies an integer from 0 to 255.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To feed paper by 30 dots:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addFeedUnit(30);
}
//-->
</script>
Chapter 4 API Reference
addFeedLine method
Adds paper feeding in lines to the command buffer.
Syntax addFeedLine
(line);
Parameter
line :
( Required parameter, Object type : Number)
Specifies the paper feed space (in lines). Specifies an integer from 0 to 255.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To feed paper by 3 lines:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addFeedLine(3);
}
//-->
</script>
4
71
72 addFeedPosition method
Adds label/black mark paper feeding to the command buffer.
• Control of label paper/black mark paper must be done in the standard mode.
• In the page mode, addFeedPosition method specification cannot be used.
Syntax addFeedPosition
(pos);
Parameter
pos :
( Required parameter, Object type : String)
Specifies the feed position.
Setting
FEED_PEELING
FEED_CUTTING
FEED_CURRENT_TOF
FEED_NEXT_TOF
Description
Feeds to the peeling position.
Feeds to the cutting position.
Feeds to the top of the current label.
Feeds to the top of the next label.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To print while peeling the label one by one
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addFeedPosition(builder.FEED_CURRENT_TOF);
builder.addBarcode('0001', builder.BARCODE_CODE39, builder.HRI_BELOW);
builder.addFeedPosition(builder.FEED_PEELING);
}
//-->
</script>
To print labels consecutively
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addFeedPosition(builder.FEED_CURRENT_TOF);
builder.addBarcode('0001', builder.BARCODE_CODE39, builder.HRI_BELOW);
builder.addFeedPosition(builder.NEXT_TOF);
builder.addBarcode('0002', builder.BARCODE_CODE39, builder.HRI_BELOW);
builder.addFeedPosition(builder.NEXT_TOF);
builder.addBarcode('0003', builder.BARCODE_CODE39, builder.HRI_BELOW);
builder.addFeedPosition(builder.NEXT_TOF);
}
//-->
</script>
To print tickets with black mark paper
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addFeedPosition(builder.FEED_CURRENT_TOF);
builder.addBarcode('0001', builder.BARCODE_CODE39, builder.HRI_BELOW);
builder.addFeedPosition(builder.FEED_CUTTING);
builder.addCut(builder.CUT_NO_FEED);
}
//-->
</script>
4
73
74 addFeed method
Adds a line feed to the command buffer.
Syntax addFeed
();
Return value
Return value
ePOS-Print Builder Object
Object type
ePOS Builder
Example
To start a new line after printing a character string:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addText(“Hello”).addFeed();
builder.addText(“World”).addFeed();
}
//-->
</script>
Chapter 4 API Reference
addImage method
Adds raster image printing to the command buffer.
Prints graphics rendered in HTML5 Canvas.
• To print a raster image at high speed, specify ALIGN_LEFT for the addTextAlign method (
), and specify a multiple of 8 not exceeding the printer's paper width for the width parameter of this API.
• In page mode, a raster image is laid out in the current print position with the reference point being its bottom left dot. The print position will not move.
If an HTML5 Canvas image contains images downloaded from different domains, you cannot print the image. In this case, a security error occurs due to violation of the same origin policy of
JavaScript.
Syntax addImage
(context, x, y, width, height, color, mode);
Parameter
context :
x :
y :
width :
height :
color :
( Required parameter, Object type : Context)
Specifies the 2D context of HTML5 Canvas.
( Required parameter, Object type : Number)
Specifies the horizontal start position in the print area. Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical start position in the print area. Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the width of the print area. Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the height of the print area. Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the color.
Setting
COLOR_NONE
COLOR_1 (default)
COLOR_2
COLOR_3
COLOR_4 undefined
(When not specified)
Description
Characters are not printed.
First color
Second color
Third color
Fourth color
First color
mode :
( Optional parameter, Object type : String)
Specifies the color mode.
Setting
MODE_MONO
MODE_GRAY16 undefined
(When not specified)
Description
Monochrome (two-tone)
Gray scale (16-tone)
Monochrome (two-tone)
4
75
76
Return value
ePOS-Print Builder Object
Return value
Exception
Exception
Parameter " ... " is invalid
Example
Object type
ePOS Builder
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var context = canvas.getContext('2d');
builder.addImage(context, 0, 0, canvas.width, canvas.height);
}
}
//-->
</script>
To print an image 300 dots wide and 300 dots high in page mode:
var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var builder = new epson.ePOSBuilder(); builder.addPageBegin(); builder.addPageArea(0, 0, 300, 300); builder.addPagePosition(0, 299); builder.addImage(context, 0, 0, 300, 300); builder.addPageEnd();
Chapter 4 API Reference
addLogo method
Adds NV logo printing to the command buffer.
Prints a logo registered in the NV memory of the printer.
• Using model-dedicated utility or logo registration utility (TMFLogo), register a logo in the printer in advance.
• In page mode, a logo is laid out in the current print position with the reference point being its bottom left dot.
Syntax addLogo
(key1, key2);
Parameter
key1 :
key2 :
( Required parameter, Object type : Number)
Specifies the key code 1 of an NV logo. Specifies an integer from 0 to 255.
( Required parameter, Object type : Number)
Specifies the key code 2 of an NV logo. Specifies an integer from 0 to 255.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Exception
Error
Object type
Parameter " ... " is invalid
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addLogo(48, 48);
}
//-->
</script>
4
77
78 addBarcode method
Adds barcode printing to the command buffer.
In page mode, a barcode is laid out in the current print position with the reference point being its bottom left dot (except for HRI).
Syntax addBarcode
(data, type, hri, font, width, height);
Parameter
data :
( Required parameter, Object type : String)
Specifies the barcode data as a string.
Barcode type
UPC-A
UPC-E
EAN13
JAN13
EAN8
JAN8
CODE39
ITF
CODABAR
Description
When an 11-digit number is specified, a check digit is automatically added.
When a 12-digit number is specified, the 12th digit is processed as a check digit but the check digit is not validated.
Specify 0 as the first digit.
Specify the manufacturer code in the digits 2 to 6.
Specify (right-align) the item code in the digits 7 to 11.
The number of item code digits varies depending on the manufacturer code. Specify 0s in empty digits.
When an 11-digit number is specified, a check digit is automatically added.
When a 12-digit number is specified, the 12th digit is processed as a check digit but the check digit is not validated.
When an 12-digit number is specified, a check digit is automatically added.
When a 13-digit number is specified, the 12th digit is processed as a check digit but the check digit is not validated.
When a 7-digit number is specified, a check digit is automatically added.
When an 8-digit number is specified, the 8th digit is processed as a check digit but the check digit is not validated.
When the first character is *, the character is processed as the start character. In other cases, a start character is automatically added.
Start and stop codes are automatically added.
Check digits are not added or validated.
Specify a start character (A to D, a to d).
Specify a stop character (A to D, a to d).
Check digits are not added or validated.
Chapter 4 API Reference
Barcode type
CODE93
CODE128
GS1-128
Description
Start and stop characters are automatically added.
A check digit is automatically calculated and added.
Specify a start character (CODE A, CODE B, CODE C).
A stop character is automatically added.
A check digit is automatically calculated and added.
To encode each of the following characters, specify two characters starting with the character "{":
< How to specify special characters >
*1
< How to specify CODE C >
*2
A start character, FNC1, a check digit, and a stop character are automatically added.
To automatically calculate and add a check digit for an application identifier (AI) and the subsequent data, specify the character "*" in the position of the check digit.
You can enclose an application identifier (AI) in parentheses. The parentheses are used as HRI print characters and are not encoded as data.
You can insert spaces between an application identifier
(AI) and data. The spaces are used as HRI print characters and are not encoded as data.
To encode each of the following characters, specify two characters starting with the character "{":
< How to specify special characters >
*3
< How to specify CODE C >
*2
GS1 DataBar Omnidirectional
GS1 DataBar Truncated
GS1 DataBar Limited
Specify a 13-digit global trade item number (GTIN) not including an application identifier (AI) or a check digit.
GS1 DataBar Expanded
You can enclose an application identifier (AI) in parentheses. The parentheses are used as HRI print characters and are not encoded as data.
To encode each of the following characters, specify two characters starting with the character "{":
< How to specify special characters >
*4
4
79
80
To specify binary data that cannot be represented by character strings, use the following escape sequences.
String Description
\xnn
\\
Control code
Back slash
*1: How to specify Code128 special characters
Data Specified character string
FNC1
FNC2
FNC3
FNC4
CODE A
CODE B
CODE C
SHIFT
{
{A
{B
{1
{S
{{
{C
{2
{3
{4
*2: How to specify Code128 CODE C and GS1-128 CODE C.
Data Specified character string
00
01
\x00
\x01
...
09
10
\x09
\x0a
...
98
99
\x62 or b
\x63 or c
*3: How to specify GS1-128 special characters
Data
)
*
{
FNC1
FNC3
(
{)
{*
{{
{1
{3
{(
Specified character string
*4: How to specify GS1 DataBar Expanded special characters
Data Specified character string
FNC1
(
)
{1
{(
{)
type :
hri :
font :
width :
height :
Chapter 4 API Reference
( Required parameter, Object type : String)
Specifies the barcode type.
Constant (type)
BARCODE_UPC_A
BARCODE_UPC_E
BARCODE_EAN13
BARCODE_JAN13
BARCODE_EAN8
BARCODE_JAN8
BARCODE_CODE39
BARCODE_ITF
BARCODE_CODABAR
BARCODE_CODE93
BARCODE_CODE128
BARCODE_GS1_128
BARCODE_GS1_DATABAR_OMNIDIRECTIONAL
BARCODE_GS1_DATABAR_TRUNCATED
BARCODE_GS1_DATABAR_LIMITED
BARCODE_GS1_DATABAR_EXPANDED
Barcode type
UPC-A
UPC-E
EAN13
JAN13
EAN8
JAN8
CODE39
ITF
CODABAR
CODE93
CODE128
GS1-128
GS1 DataBar Omnidirectional
GS1 DataBar Truncated
GS1 DataBar Limited
GS1 DataBar Expanded
( Optional parameter, Object type : String)
Specifies the HRI position.
Constant (hri)
HRI_NONE (default)
HRI_ABOVE
HRI_BELOW
HRI_BOTH
Description
HRI not printed
Above the barcode
Below the barcode
Both above and below the barcode
( Optional parameter, Object type : String)
Specifies the HRI font.
Constant (font)
FONT_A(default)
FONT_B
FONT_C
FONT_D
FONT_E
Font A
Font B
Font C
Font D
Font E
Language
( Optional parameter, Object type : Number)
Specifies the width of each module in dots. Specifies an integer from 2 to 6.
( Optional parameter, Object type : Number)
Specifies the barcode height in dots. Specifies an integer from 1 to 255.
4
81
82
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To print barcodes:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addBarcode('01234567890', builder.BAROCDE_UPC_A, builder.HRI_BELOW, undefined, 2, 64);
builder.addBarcode('01234500005', builder.BAROCDE_UPC_E);
builder.addBarcode('201234567890', builder.BAROCDE_EAN13);
builder.addBarcode('201234567890', builder.BAROCDE_JAN13);
builder.addBarcode('2012345', builder.BAROCDE_EAN8);
builder.addBarcode('2012345', builder.BAROCDE_JAN8);
builder.addBarcode('ABCDE', builder.BAROCDE_CODE39);
builder.addBarcode('012345', builder.BAROCDE_ITF);
builder.addBarcode('A012345A', builder.BAROCDE_CODABAR);
builder.addBarcode('ABCDE', builder.BAROCDE_CODE93);
builder.addBarcode('{AABCDE', builder.BARCODE_CODE128);
builder.addBarcode('{Babcde', builder.BARCODE_CODE128);
builder.addBarcode('{C\x0c\x22', builder.BARCODE_CODE128);
builder.addBarcode('(01)201234567890*', builder.BAROCDE_GS1_128);
builder.addBarcode('0201234567890', builder.BAROCDE_GS1_DATABAR_OMNIDIRECTIONAL);
builder.addBarcode('0201234567890', builder.BAROCDE_GS1_DATABAR_TRUNCATED);
builder.addBarcode('0201234567890', builder.BAROCDE_GS1_DATABAR_LIMITED);
builder.addBarcode('(01)2012345678903', builder.BAROCDE_GS1_DATABAR_EXPANDED);
}
//-->
</script>
Chapter 4 API Reference
addSymbol method
Adds 2D-code printing to the command buffer.
In page mode, a 2D-code is laid out in the current print position with the reference point being its bottom left dot.
Syntax addSymbol
(data, type, level, width, height, size);
Parameter
data :
( Required parameter, Object type : String)
Specifies 2D‐code data as a character string.
2D-Code type
Standard PDF417
Truncated PDF417
QR Code Model 1
QR Code Model 2
Micro QR Code *1
Description
Convert the character string to the string in UTF-
8, apply the escape sequence, and then encode the string.
The data area can contain up to 928 code words in a maximum of 90 rows, each of which can contain up to 30 code words.
Convert the character string to the string in Shift-
JIS, apply the escape sequence, and then encode the string based on the data type as shown below.
Number: 0 to 9
Alphanumeric character:
0 to 9, A to Z, space, $, %, *, +, -, ., /, :
Kanji character: Shift-JIS value
8-bit, byte data:
0x00 to 0xff
4
83
84
2D-Code type
MaxiCode Mode 2
MaxiCode Mode 3
MaxiCode Mode 4
MaxiCode Mode 5
MaxiCode Mode 6
GS1 DataBar Stacked
GS1 DataBar Stacked
Omnidirectional
GS1 DataBar Expanded Stacked
Aztec Code
DataMatrix
Description
Convert the character string to the string in UTF-
8, apply the escape sequence, and then encode the string.
In Modes 2 and 3, when the first piece of data is
[)>\ x1e01\x1dyy (where yy is a two-digit number), this is processed as the message header, and the subsequent data is processed as the primary message. In other cases, from the first piece of data, data is processed as the primary message.
In Mode 2, specify the primary message in the following format:
Postal code (1- to 9-digit number) GS:(\x1d) ISO country code (1- to 3-digit number) GS:(\x1d)
Service class code (1- to 3-digit number)
In Mode 3, specify the primary message in the following format:
Postal code (1 to 6 pieces of data convertible by Code Set A) GS:(\x1d) ISO country code (1- to 3-digit number) GS:(\x1d) Service class code
(1- to 3-digit number)
Convert the character string to the string in UTF-
8, apply the escape sequence, and then encode the string.
Specify a 13-digit global trade item number
(GTIN) not including an application identifier
(AI) or a check digit.
Convert the character string to the string in UTF-
8, apply the escape sequence, and then encode the string.
You can enclose an application identifier (AI) in parentheses. The parentheses are used as HRI print characters and are not encoded as data.
(:
):
To encode each of the following characters, specify two characters starting with the character "{":
FNC1: {1
{(
{)
After converting the character string to UTF-8, conduct the escape sequence and encode.
After converting the character string to UTF-8, conduct the escape sequence and encode.
*1: ePOS-Print Service Ver.4.1 or later
type :
Chapter 4 API Reference
To specify binary data that cannot be represented by character strings, use the following escape sequences.
String Description
\xnn
\\
Control code
Back slash
( Required parameter, Object type : String)
Specifies the 2D‐code type.
Constant (type) 2D-Code type
SYMBOL_PDF417_STANDARD
SYMBOL_PDF417_TRUNCATED
SYMBOL_QRCODE_MODEL_1
SYMBOL_QRCODE_MODEL_2
SYMBOL_QRCODE_MICRO
SYMBOL_MAXICODE_MODE_2
SYMBOL_MAXICODE_MODE_3
SYMBOL_MAXICODE_MODE_4
Standard PDF417
Truncated PDF417
QR Code Model 1
QR Code Model 2
Micro QR Code
MaxiCode Mode 2
MaxiCode Mode 3
MaxiCode Mode 4
SYMBOL_MAXICODE_MODE_5
SYMBOL_MAXICODE_MODE_6
MaxiCode Mode 5
MaxiCode Mode 6
SYMBOL_GS1_DATABAR_STACKED
SYMBOL_GS1_DATABAR_STACKED_
OMNIDIRECTIONAL
GS1 DataBar Stacked
GS1 DataBar Stacked
Omnidirectional
SYMBOL_GS1_DATABAR_EXPANDED_STACKED GS1 DataBar Expanded Stacked
SYMBOL_AZTECCODE_FULLRANGE
SYMBOL_AZTECCODE_COMPACT
SYMBOL_DATAMATRIX_SQUARE
SYMBOL_DATAMATRIX_RECTANGLE_8
SYMBOL_DATAMATRIX_RECTANGLE_12
SYMBOL_DATAMATRIX_RECTANGLE_16
Aztec Code Full-Range mode
Aztec Code Compact mode
DataMatrix ECC200 square
DataMatrix ECC200 rectangle,
8 lines
DataMatrix ECC200 rectangle,
12 lines
DataMatrix ECC200 rectangle,
16 lines
4
85
86
level :
width :
height :
( Optional parameter, Object type : String)
Specifies the error correction level.
Constant (level)
LEVEL_0
LEVEL_1
LEVEL_2
LEVEL_3
LEVEL_4
LEVEL_5
LEVEL_6
LEVEL_7
LEVEL_8
LEVEL_L
LEVEL_M
LEVEL_Q
LEVEL_H
LEVEL_DEFAULT
Integer from 5 to 95
Description
PDF417 error correction level 0
PDF417 error correction level 1
PDF417 error correction level 2
PDF417 error correction level 3
PDF417 error correction level 4
PDF417 error correction level 5
PDF417 error correction level 6
PDF417 error correction level 7
PDF417 error correction level 8
QR Code error correction level L
QR Code error correction level M
QR Code error correction level Q
QR Code error correction level H
Default level
Aztec Code error correction level (Default: 23)
• Select the level according to the 2D-code type.
• For MaxiCode and two-dimensional GS1 DataBar, select LEVEL_DEFAULT.
• Micro QR Code does not support LEVEL_H.
( Optional parameter, Object type : Number)
Specifies the module width. Specifies an integer from 0 to 255.
2D-Code type
PDF417
QR Code
MaxiCode
2D GS1 DataBar
Aztec Code
DataMatrix
Valid value range
2 to 8
1 to 16
Ignored
2 to 8
2 to 16
2 to 16
( Optional parameter, Object type : Number)
Specifies the module height. Specifies an integer from 0 to 255.
2D-Code type
PDF417
Valid value range
2 to 8
(Magnification for width)
QR Code
MaxiCode
2D GS1 DataBar
Aztec Code
DataMatrix
Ignored
3
3
2
3
3
3
Default value
Default value
Chapter 4 API Reference
size :
( Optional parameter, Object type : Number)
Specifies the 2D‐code maximum size. Specifies an integer from 0 to 65535.
2D-Code type Default value
PDF417 0 (Auto)
Description
Specifies the number of code words for each row
QR Code
MaxiCode
Ignored
2D GS1 DataBar 0 (Auto)
Specifies the maximum width for the barcode
(106 or above)
Aztec Code
DataMatrix
(Others)
Ignored
Ignored
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Example
To print 2D-codes:
Exception
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addSymbol('ABCDE', builder.SYMBOL_PDF417_STANDARD);
builder.addSymbol('ABCDE', builder.SYMBOL_QRCODE_MODEL_2, builder.LEVEL_Q);
builder.addSymbol('908063840\x1d850\x1d001\x1d\x04', builder.SYMBOL_MAXICODE_MODE_2);
builder.addSymbol('0201234567890', builder.SYMBOL_
GS1_DATABAR_STACKED);
builder.addSymbol('0201234567890', builder.SYMBOL_GS1_DATABAR_STACKED_OMNIDIRECTIONAL);
builder.addSymbol('(01)02012345678903', builder.SYMBOL_GS1_DATABAR_EXPANDED_STACKED);
builder.addSymbol('ABCDE', builder.SYMBOL_AZTECCODE_FULLRANGE, 23);
builder.addSymbol('ABCDE', builder.SYMBOL_DATAMATRIX_SQUARE);
}
//-->
</script>
4
87
88 addHLine method
Adds horizontal line printing to the command buffer.
Draws horizontal lines.
Not available in page mode.
Syntax addHLine
(x1, x2, style);
Parameter
x 1:
x2 :
style :
( Required parameter, Object type : Number)
Specifies the start position of the horizontal line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the end position of the horizontal line (in dots). Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the line type.
Constant (style)
LINE_THIN
LINE_MEDIUM
LINE_THICK
LINE_THIN_DOUBLE
LINE_MEDIUM_DOUBLE
LINE_THICK_DOUBLE undefined (When not specified)
Description
Solid line: Thin
Solid line: Medium
Solid line: Thick
Double line: Thin
Double line: Medium
Double line: Thick
Solid line: Thin
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To draw double horizontal lines in the following positions:
Between 100 dots and 200 dots from the left end
Between 400 dots and 500 dots from the left end
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addHLine(100, 200, builder.LINE_THIN_DOUBLE);
builder.addHLine(400, 500, builder.LINE_THIN_DOUBLE);
}
//-->
</script>
4
89
90 addVLineBegin method
Adds the beginning of vertical line to the command buffer. Starts to draw vertical lines.
Not available in page mode.
Vertical lines are drawn until their end is specified by addVLineEnd ( p. 92
). Use this API function with addVLineEnd.
Syntax addVLineBegin
(x, style);
Parameter
x :
style :
( Required parameter, Object type : Number)
Specifies the start position of the vertical line (in dots). Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the line type.
Constant (style)
LINE_THIN
LINE_MEDIUM
LINE_THICK
LINE_THIN_DOUBLE
LINE_MEDIUM_DOUBLE
LINE_THICK_DOUBLE undefined (When not specified)
Description
Solid line: Thin
Solid line: Medium
Solid line: Thick
Double line: Thin
Double line: Medium
Double line: Thick
Solid line: Thin
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To draw thin vertical lines at 100 dots and 200 dots from the left end:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addVLineBegin(100).addVLineBegin(200);
builder.addFeedUnit(100);
builder.addVLineEnd(100).addVLineEnd(200);
}
//-->
</script>
4
91
92 addVLineEnd method
Adds the end of vertical line to the command buffer. Finishes drawing vertical lines.
Not available in page mode.
Use this API function with addVLineBegin ( p. 90
).
Syntax addVLineEnd
(x, style);
Parameter
x :
style :
( Required parameter, Object type : Number)
Specifies the end position of the vertical line (in dots). Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the type of the line you want to finish drawing.
Constant (style)
LINE_THIN
LINE_MEDIUM
LINE_THICK
LINE_THIN_DOUBLE
LINE_MEDIUM_DOUBLE
LINE_THICK_DOUBLE undefined (When not specified)
Description
Solid line: Thin
Solid line: Medium
Solid line: Thick
Double line: Thin
Double line: Medium
Double line: Thick
Solid line: Thin
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To draw thin vertical lines at 100 dots and 200 dots from the left end:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addVLineBegin(100).addVLineBegin(200);
builder.addFeedUnit(100);
builder.addVLineEnd(100).addVLineEnd(200);
}
//-->
</script>
4
93
94 addPageBegin method
Adds the switching to page mode to the command buffer. The page mode process starts.
Vertical lines are processed in page mode until their end is specified by addPageEnd (
). Use this API function with addPageEnd.
Syntax addPageBegin
();
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Example
To print the characters "ABCDE" in page mode:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addText('ABCDE');
builder.addPageEnd();
}
//-->
</script>
Chapter 4 API Reference
addPageEnd method
Adds the end of page mode to the command buffer. The page mode process ends.
Use this API function with addPageBegin ( p. 94
).
Syntax addPageEnd
();
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Example
To print the characters "ABCDE" in page mode:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addText('ABCDE');
builder.addPageEnd();
}
//-->
</script>
4
95
96 addPageArea method
Adds the print area in page mode to the command buffer.
Specifies the print area in page mode (coordinates). After this API function, specify a print data API function such as the addText method.
Specify a print area to cover the content to be printed. If the print data extends beyond the print area, the print result will be such that the print data has been printed incompletely.
Use this API function by inserting it between addPageBegin ( p. 94
).
Syntax addPageArea
(x, y, width, height);
Parameter
x :
y :
width :
height :
( Required parameter, Object type : Number)
Specifies the origin of the horizontal axis (in dots). Specifies an integer from 0 to 65535. 0 is the left end of the printer’s printable area.
( Required parameter, Object type : Number)
Specifies the origin of the vertical axis (in dots). Specifies an integer from 0 to 65535. 0 is the position in which no paper feed has been performed.
( Required parameter, Object type : Number)
Specifies the width of the print area (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the height of the print area (in dots). Specifies an integer from 0 to 65535.
Determine the width and height of the print area according to the print direction setting. Otherwise, the print data might not be printed completely.
Return value
ePOS-Print Builder Object
Return value
Exception
Exception
Parameter " ... " is invalid
Object type
ePOS Builder
Error
Object type
Chapter 4 API Reference
Example
To specify the print area with the origin (100, 50), a width of 200 dots, and a height of 30 dots and print the characters "ABCDE":
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addPageArea(100, 50, 200, 30);
builder.addText('ABCDE');
builder.addPageEnd();
}
//-->
</script>
4
97
98 addPageDirection method
Adds the page mode print direction setting to the command buffer. Specifies the print direction in page mode. This function can be omitted if rotation is not required.
Use this API function by inserting it between addPageBegin ( p. 94
).
Syntax addPageDirection
(dir);
Parameter
dir :
( Required parameter, Object type : String)
Specifies the print direction in page mode.
Constant (dir)
DIRECTION_LEFT_TO_RIGHT(default)
DIRECTION_BOTTOM_TO_TOP
DIRECTION_RIGHT_TO_LEFT
DIRECTION_TOP_TO_BOTTOM
Description
Left to right
(No rotation.Data is printed from the top left corner to the right.)
Bottom to top
(Counterclockwise rotation by 90 degrees.
Data is printed from the bottom left corner to the top.)
Right to left
(Rotation by 180 degrees.Data is printed from the bottom right corner to the left.)
Top to bottom
(Clockwise rotation by 90 degrees.
Data is printed from the top right corner to the bottom.)
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To print the characters "ABCDE" by rotating them 90 degrees clockwise:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addPageArea(100, 50, 30, 200);
builder.addPageDirection(builder.DIRECTION_TOP_TO_BOTTOM);
builder.addText('ABCDE');
builder.addPageEnd();
}
//-->
</script>
4
99
100 addPagePosition method
Adds the page mode print-position-set area to the command buffer.
Specifies the print start position (coordinates) in the area specified by the addPageArea method.
Use this API function by inserting it between addPageBegin ( p. 94
).
Syntax addPagePosition
(x, y);
Parameter
x :
y :
( Required parameter, Object type : Number)
Specifies the horizontal print position (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical print position (in dots). Specifies an integer from 0 to 65535.
Specify the print start position (coordinates) according to the content to be printed. Refer to the following.
To print a character string:
Specify the left end of the baseline for the first character. This can be omitted for left-aligned printing of standard-sized characters. To print double-sized height characters, specify a value equal to or greater than 42 for y.
To print a barcode:
Specify the bottom left of the symbol. And specify the barcode height for y.
To print a graphic/logo:
Specify the bottom left of the graphic data. And specify the graphic data height for y.
To print a 2D-code:
Specify the top left of the symbol. This can be omitted when printing from the top left.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To specify (50,30) for the print start position in the area specified by the addPageArea method and print the characters "ABCDE":
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addPageArea(100, 50, 200, 100);
builder.addPagePosition(50, 30);
builder.addText('ABCDE');
builder.addPageEnd();
}
//-->
</script>
4
101
102 addPageLine method
Adds line drawing in page mode to the command buffer. Draws a line in page mode.
Diagonal lines cannot be drawn.
Use this API function by inserting it between addPageBegin ( p. 94
).
Syntax addPageLine
(x1, y1, x2, y2, style);
Parameter
x 1:
y 1:
x2 :
y2 :
style :
( Required parameter, Object type : Number)
Specifies the horizontal start position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical start position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the horizontal end position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical end position of the line (in dots). Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the line type.
Constant (style)
LINE_THIN
LINE_MEDIUM
LINE_THICK
LINE_THIN_DOUBLE
LINE_MEDIUM_DOUBLE
LINE_THICK_DOUBLE undefined
(When not specified)
Description
Solid line: Thin
Solid line: Medium
Solid line: Thick
Double line: Thin
Double line: Medium
Double line: Thick
Solid line: Thin
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To draw a thin solid line between the start position (100, 0) and the end position (500, 0):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addPageLine(100, 0, 500, 0, builder.LINE_THIN);
builder.addPageEnd();
}
//-->
</script>
4
103
104 addPageRectangle method
Adds rectangle drawing in page mode to the command buffer. Draws a rectangle in page mode.
Use this API function by inserting it between addPageBegin ( p. 94
).
Syntax addPageRectangle
(x1, y1, x2, y2, style);
Parameter
x 1:
y 1:
x2 :
y2 :
style :
( Required parameter, Object type : Number)
Specifies the horizontal start position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical start position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the horizontal end position of the line (in dots). Specifies an integer from 0 to 65535.
( Required parameter, Object type : Number)
Specifies the vertical end position of the line (in dots). Specifies an integer from 0 to 65535.
( Optional parameter, Object type : String)
Specifies the line type.
Constant (style)
LINE_THIN
LINE_MEDIUM
LINE_THICK
LINE_THIN_DOUBLE
LINE_MEDIUM_DOUBLE
LINE_THICK_DOUBLE undefined (When not specified)
Description
Solid line: Thin
Solid line: Medium
Solid line: Thick
Double line: Thin
Double line: Medium
Double line: Thick
Solid line: Thin
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Chapter 4 API Reference
Example
To draw a rectangle with a thin double line, with the start position (100, 0) and the end position (500,
200) as its vertexes:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPageBegin();
builder.addPageLine(100, 0, 500, 200, builder.LINE_THIN_DOUBLE);
builder.addPageEnd();
}
//-->
</script>
4
105
106 addCut method
Adds paper cut to the command buffer. Sets paper cut.
Not available in page mode.
Syntax addCut
(type);
Parameter
type :
( Optional parameter, Object type : String)
Specifies the paper cut type.
Setting
CUT_NO_FEED
CUT_FEED
CUT_RESERVE undefined
(When not specified)
Description
Cut without feeding
(The paper is cut without being fed.)
Feed cut
(The paper is fed to the cut position and then is cut.)
Cut reservation
(Printing continues until the cut position is reached, at which the paper is cut.)
Feed cut
(The paper is fed to the cut position and then is cut.)
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To perform feed cut operation:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addCut(builder.CUT_FEED);
}
//-->
</script>
Chapter 4 API Reference
addPulse method
Adds the drawer kick to the command buffer. Sets the drawer kick.
• Not available in page mode.
• The drawer and the buzzer cannot be used together.
Syntax addPulse
(drawer, time);
Parameter
drawer :
( Optional parameter, Object type : String)
Specifies the drawer kick connector.
Setting
DRAWER_1
DRAWER_2 undefined
(When not specified)
Description
Pin 2 of the drawer kick-out connector
Pin 5 of the drawer kick-out connector
Pin 2 of the drawer kick-out connector
time :
( Optional parameter, Object type : String)
Specifies the ON time of the drawer kick signal.
Setting
PULSE_100
PULSE_200
PULSE_300
PULSE_400
PULSE_500 undefined
(When not specified)
100 ms
200 ms
300 ms
400 ms
500 ms
100 ms
Description
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
4
107
108
Example
To send a 100msec pulse signal to the pin 2 of the drawer kick connector:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addPulse(builder.DRAWER_1, builder.PULSE_100);
}
//-->
</script>
Chapter 4 API Reference
addSound method
Adds the turning on of the buzzer to the command buffer. Sets the buzzer.
• Not available in page mode.
• The buzzer function and the drawer cannot be used together.
• This API function cannot be used if the printer is not provided with the buzzer.
Syntax addSound
(pattern, repeat, cycle);
Parameter
pattern :
Setting
PATTERN_NONE
PATTERN_A
PATTERN_B
PATTERN_C
PATTERN_D
PATTERN_E
PATTERN_ERROR
PATTERN_PAPER_END
PATERN_0 *
PATERN_1
PATERN_2
PATERN_3
PATERN_4
PATERN_5
PATERN_6
PATERN_7
PATERN_8
PATERN_9
PATERN_10 undefined
(When not specified)
( Optional parameter, Object type : String)
Specifies the buzzer pattern.
Description
Stop
Pattern A
Pattern B
Pattern C
Pattern D
Pattern E
Error sound pattern
Pattern when there is no paper
Pattern 0
Pattern 1
Pattern 2
Pattern 3
Pattern 4
Pattern 5
Pattern 6
Pattern 7
Pattern 8
Pattern 9
Pattern 10
Pattern A
*: ePOS-Print Service Ver.5.0 or later
4
109
110
repeat :
cycle :
( Optional parameter, Object type : String)
Specifies the number of repeats.
Setting
0
1 to 255
Description
The buzzer does not stop.
Number of repeats
(For PATTERN_0, the effective range is between 1 to 20.) undefined
(When not specified)
One time
After “0” is specified for repeat, if you want to stop the buzzer, execute this API function and specify PATTERN_NONE for pattern.
(Optional parameter, Object type : Number, When not specified : 1000)
Specifies the buzzer sounding cycle. Specifies an integer from 1000 to 25500.
"cycle" is enabled by any of "pattern_0" to "pattern_10" for the buzzer pattern.
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
To repeat the sound pattern A three times:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addSound(builder.PATTERN_A, 3);
}
//-->
</script>
Chapter 4 API Reference
addLayout method
Adds paper layout information to the command buffer.
Setting of page layout must be done in the standard mode. In the page mode, addLayout cannot be specified.
Syntax addLayout
(type, width, height, margin_top,
margin_bottom, offset_cut, offset_label);
Parameter
type :
( Required parameter, Object type : String)
Specifies the paper type.
Constant (type)
LAYOUT_RECEIPT
LAYOUT_RECEIPT_BM
LAYOUT_LABEL
LAYOUT_LABEL_BM
Description
Receipt (without black mark)
Receipt (with black mark)
Die-cut label (without black mark)
Die-cut label (with black mark)
width :
height :
( Optional parameter, Object type : Number, When not specified : 580)
Specifies paper width (in units of 0.1 mm). Specifies an integer from 290 to 600. *
( Optional parameter, Object type : Number, When not specified : 0)
Specifies paper height (in units of 0.1 mm).
Paper Type
Receipt
(without black mark)
0
Valid value range Description
Setup not necessary
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
0 (Auto)
284 to 1550 (Manual) *
Distance from the top of black mark to the top of next black mark
Distance from the top of label to the top of next label
Distance from the bottom of black mark to the bottom of next black mark.
margin_top :
( Optional parameter, Object type : Number, When not specified : 0)
Specifies top margin (in units of 0.1 mm).
Valid value range Paper Type
Receipt
(without black mark)
0
Description
Setup not necessary
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
-150 to 1500 *
0 to 1500 *
-15 to 1500 *
Distance from the top of black mark
Distance from the top of label
Distance from the bottom of black mark
111
4
112
margin_bottom :( Optional parameter, Object type : Number, When not specified : 0)
Specifies bottom margin (in units of 0.1 mm).
Valid value range Paper Type
Receipt
(without black mark)
Receipt (with black mark)
0
0
Description
Setup not necessary
Die-cut label
(without black mark)
Die-cut label
(with black mark)
-15 to 0 *
-15 to 15 *
Distance from the bottom of label (paper feed direction is a positive number)
Distance from the top of black mark (paper feed direction is a positive number)
offset_cut :
( Optional parameter, Object type : Number, When not specified : 0)
Specifies cut position (in units of 0.1 mm).
In case of die cut label paper, it is a distance from the bottom of label.
When a paper has black mark, it is a distance from the beginning of black mark.
Valid value range Description Paper Type
Receipt
(without black mark)
0 Setup not necessary
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
-290 to 50 *
0 to 50 *
0 to 50 *
Distance from the top of black mark to the cutting position
Distance from the bottom of label to the cutting position
Distance from the top of black mark to the cutting position
offset_label* :
( Optional parameter, Object type : Number, When not specified : 0)
Specifies label bottom position (sd) per 0.1 mm unit.
Valid value range Paper Type
Receipt
(without black mark)
Receipt (with black mark)
Die-cut label
(without black mark)
0
0
0
Description
Setup not necessary
Die-cut label
(with black mark)
0 to 15 *
Distance from the top of black mark to the bottom of label
*: Valid value of range is depending on the printer model. For detail, refer to Printer specifications (p.183) .
Chapter 4 API Reference
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Detailed description
See below for the parameters that can be specified for each type of paper, and the positions for those parameters.
Mark sf sa sb se sc sd
Parameter
width height margin_top margin_bottom offset_cut offset_label
<without Black Mark> sf
<with Black Mark> sf sb sc
Top position
Cut
Receipt sa
4
Label
Top position
Cut
sf sb
Bottom edge of print area
se sa sc sc sf
Cut
sb
Top position
Bottom edge of label
Bottom edge of print area
Standard eject
se sd sa sc
113
114
Example
To set 58 mm receipt (without black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addLayout(builder.LAYOUT_RECEIPT, 580);
}
//-->
</script>
To set 58 mm receipt (with black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addLayout(builder.LAYOUT_RECEIPT_BM, 580, 0, 15, 0);
}
//-->
</script>
To set 58 mm die-cut label (without black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addLayout(builder.LAYOUT_LABEL, 580, 0, 15, -15, 25);
}
//-->
</script>
To set 58 mm die-cut label (with black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addLayout(builder.LAYOUT_LABEL_BM, 580, 0, 15, -15, 25, 15);
}
//-->
</script>
Chapter 4 API Reference
addRecovery method
Adds the recovery from errors to the command buffer.
Enable forced transmission mode to use this API. The printer recovers from errors that can be recovered from and clears the buffer.
Syntax addRecovery
();
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
Recovers from errors that can be recovered from and clears the buffer:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.force = true;
builder.addRecovery();
}
//-->
</script>
4
115
116 addReset method
Adds the printer reset to the command buffer.
Other printing commands in the print document are ignored.
Syntax addReset
();
Return value
ePOS-Print Builder Object
Return value Object type
ePOS Builder
Exception
Parameter " ... " is invalid
Exception
Error
Object type
Example
Resets the printer:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.addReset();
}
//-->
</script>
Chapter 4 API Reference
addCommand method
Adds commands to the command buffer. Sends ESC/POS commands.
Refer to the following URL for details of the ESC/POS command.
https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=2
Syntax addCommand
(data);
Parameter
data :
(Optional parameter, Object type : String)
Specifies ESC/POS command as a character string.
Return value
ePOS-Print Builder Object
Return value
Exception
Exception
Parameter " ... " is invalid
Example
Object type
ePOS Builder
Error
Object type
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
var doc = builder.addCommand('ABC\x44\x45\x0a');
}
//-->
</script>
4
117
118 toString method
Obtains a print document generated by an ePOS-Print Builder object.
Syntax toString
();
Return value
Document to be printed
Return value Object type
String
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
var doc = builder.toString();
}
//-->
</script>
Chapter 4 API Reference
halftone property
Halftone processing method.
Object type
String
Description
The halftone processing method to be applied to monochrome (two-tone) printing is specified.
The default value is HALFTONE_DITHER.
Constant
HALFTONE_DITHER (default)
HALFTONE_ERROR_DIFFUSION
HALFTONE_THRESHOLD
Description
Dithering, suitable for printing graphics only.
Error diffusion, suitable for printing text and graphics together.
Threshold, suitable for printing text only.
Example
To set the halftone type as error diffusion:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
var canvas = document.getElementById('canvas'); if (canvas.getContext) {
var context = canvas.getContext('2d');
builder.halftone = epos.HALFTONE_ERROR_DIFFUSION;
builder.addImage(context, 0, 0, canvas.width, canvas.height);
}
}
//-->
</script>
4
119
120 brightness property
Brightness correction value.
Object type
Number
Description
A gamma value in the range 0.1-10.0 is specified for the brightness correction value.
The default value is 1.0.
Example
To set brightness as 2.2:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
var canvas = document.getElementById('canvas'); if (canvas.getContext) {
var context = canvas.getContext('2d');
builder.brightness = 2.2;
builder.addImage(context, 0, 0, canvas.width, canvas.height);
}
}
//-->
</script>
Chapter 4 API Reference
force property
This is the forced transmission mode.
Object type
Boolean
Description
If you enable forced transmission mode, print commands are forcibly sent to the printer.
• Use forced transmission mode when the printer is offline. It will result in an error if the printer is online.
• The following functions are enabled in forced transmission mode.
Drawer kick-out (
)
Stopping the buzzer ( addSound method (p.109) )
Recovery from errors that can be recovered from (
)
Reset ( addReset method (p.116)
)
Sending commands in real time (
Example
Performs a drawer kick-out when the paper is at the end:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() {
var builder = new epson.ePOSBuilder();
builder.force = true;
builder.addPulse();
}
//-->
</script>
4
121
122 message property
Command buffer.
Object type
String
Description
Commands, which are usually added by methods of the ePOS-Print Builder object, can be operated directly from this property for addition or deletion.
Example
To clear the command and reset it to the initial state:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function buildMessage() { var builder = new epson.ePOSBuilder();
builder.addText('ABCDE');
builder.message = '';
}
//-->
</script>
Chapter 4 API Reference
ePOS-Print Object
Sends a print document created using an ePOS-Print Builder object to control the printer and monitor the transmission result or the communication status.
Constructor
Constructor for an ePOS-Print object. Creates a new ePOS-Print object and initializes it.
Syntax ePOSPrint
(address);
Parameter
address :
( Optional parameter, Object type : String)
Specifies the URL of the printer to send a print document to.
The URL is as follows:
http://[IP address of ePOS-Print supported TM printer]/cgi-bin/epos/ service.cgi?devid=[device ID of printer to be used for printing]&timeout=[timeout time]
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function sendMessage() {
var address = 'http://192.168.192.168/cgi-bin/epos/ service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
}
//-->
</script>
4
123
send method
Sends a print document created using an ePOS-Print Builder object.
A print document is obtained by executing the toString method ( p. 118 ) of the ePOS-Print Builder
object.
Syntax
1
send
(request);
2
send
(request, printjobid);
Parameter
request :
printjobid :
(Required parameter, Object type : String)
Specifies the print document.
( Optional parameter, Object type : String)
Specify the print job ID (ePOS‐Print Service Ver.4.1 or later)
You can use from 1 to 30 alphanumeric characters, underscore, hyphen, and period.
Exception
Exception
Parameter " ... " is invalid
XMLHttpRequest is not supported
Error
Error
Object type
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printHellowWorld() {
var builder = new epson.ePOSBuilder();
builder.addText('Hello, World!\n'); builder.addCut();
var request = builder.toString();
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onreceive = function (res) { alert(res.success); }; epos.onerror = function (err) { alert(err.status); };
epos.send(request);
}
//-->
</script>
124
Chapter 4 API Reference
open method
Enables status event operation.
Sends the status of the printer specified by the address property using an event.
Updates the status at the interval specified by the interval property.
Syntax open
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function startMonitor() {
epos.open();
} function stopMonitor() {
epos.close();
}
//-->
</script>
4
125
close method
Disables status event operation.
Syntax close
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function startMonitor() {
epos.open();
} function stopMonitor() {
epos.close();
}
//-->
</script>
126
Chapter 4 API Reference
address property
URL of the printer.
Object type
String
Description
The URL of the printer to be used for printing is specified.
The URL is shown as follows:
http://[IP address of ePOS-Print supported TM printer]/cgi-bin/epos/ service.cgi?devid=[device ID of printer to be used for printing]&timeout=[timeout time]
The default value is the address specified by the constructor.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var epos = new epson.ePOSPrint();
epos.address = 'http://192.168.192.168/cgi-bin/epos/
service.cgi?devid=local_printer';
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
//-->
</script>
enabled property
Retains the enabled/disabled setting for status event operation.
Object type
Boolean
Description
The enabled/disabled setting for status event operation is retained using a logical value. This is read-only.
The default value is false.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
alert(epos.enabled);
//-->
</script>
4
127
interval property
Specifies the interval of upgrading the status.
Object type
Number
Description
The interval of upgrading the status is specified in milliseconds.
Default value: 3000 (three seconds)
Minimum value: 1000 (one second or longer)
When an invalid value is specified, it is assumed to be 3000.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.interval = 1000;
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
//-->
</script>
status property
Hold the TM printer's status.
Object type
Number
Description
This is the status last obtained from the printer. This is read-only.
Default value: 0
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onoffline = function () {
alert(epos.status);
};
epos.open();
//-->
</script>
128
Chapter 4 API Reference
battery property
Hold the TM printer's battery status.
Object type
Number
Description
Battery status obtained from the last printer status. This is read-only.
Default value: 0
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onbatterylow = function () {
alert(epos.battery);
};
epos.open();
//-->
</script>
timeout property
Specifies connection timeout.
Object type
Number
Description
Specifies connection timeout with ePOS-Print supported printer in milliseconds. When the transmission of print document by send method times out, onerror even is generated.
Default value: 300000 (5 minutes)
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var builder = new epson.ePOSBuilder();
builder.addText('Hello, World!\n');
builder.addCut();
var request = builder.toString();
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.timeout = 60000;
epos.onreceive = function (res) { alert(res.success); };
epos.onerror = function (err) { alert(err.status); };
epos.send(request);
//-->
</script>
129
4
130 drawerOpenLevel property
Using Low or High, specify the signal line status.
Object type
Number
Description
Using Low or High, specify the signal line status of the drawer that generates the ondraweropen and ondrawerclosed events.
Setting
DRAWER_OPEN_LEVEL_LOW
(Default)
DRAWER_OPEN_LEVEL_HIGH
Signal line status
HIGH -> LOW
LOW -> HIGH
HIGH -> LOW
LOW -> HIGH
Description
ondraweropen event is generates.
ondrawerclosed event is generates.
ondrawerclosed event is generates.
ondraweropen event is generates.
Example
epos.drawerOpenLevel = epos. DRAWER_OPEN_LEVEL_HIGH;
Chapter 4 API Reference
onreceive event
This property registers the callback function and obtains a response message receipt event.
Syntax
Function (response)
Parameter of the callback function
Parameters:
Name:
Object type:
response ( See ?Properties of the response object? on page 131.
)
Response message
Object
Properties of the response object
Property
success (
) code (
status (
)
) printjobid (
Value of success
Value
true or 1 false or 0
Value of code
Value
'EPTR_AUTOMATICAL'
'EPTR_COVER_OPEN'
'EPTR_CUTTER'
'EPTR_MECHANICAL'
'EPTR_REC_EMPTY'
'EPTR_UNRECOVERABLE'
'SchemaError'
'DeviceNotFound'
'PrintSystemError'
'EX_BADPORT'
'EX_TIMEOUT'
Name
Print result
Error code
Status
Battery status
Print job ID
Object type
Boolean
String
Number
Number
String
Printing succeeded.
Printing failed.
Description
Description
An automatically recoverable error occurred
A cover open error occurred
An autocutter error occurred
A mechanical error occurred
No paper in roll paper end sensor
An unrecoverable error occurred
The request document contains a syntax error
The printer with the specified device ID does not exist
An error occurred on the printing system
An error was detected on the communication port
A print timeout occurred
4
131
132
Value of status
Constant (status)
ASB_NO_RESPONSE
ASB_PRINT_SUCCESS
Description
No response from the TM printer
Printing is successfully completed
ASB_DRAWER_KICK
ASB_BATTERY_OFFLINE
ASB_OFF_LINE
ASB_COVER_OPEN
ASB_PAPER_FEED
ASB_WAIT_ON_LINE
ASB_PANEL_SWITCH
ASB_MECHANICAL_ERR
ASB_AUTOCUTTER_ERR
ASB_UNRECOVER_ERR
ASB_AUTORECOVER_ERR
Status of the 3rd pin of the drawer kick-out connector = "H"
Battery offline status (only for applicable devices)
Offline
The cover is open
Paper is being fed by a paper feed switch operation
Waiting to be brought back online
The paper feed switch is being pressed (ON)
A mechanical error occurred
An autocutter error occurred
An unrecoverable error occurred
An automatically recoverable error occurred
ASB_RECEIPT_NEAR_END
ASB_RECEIPT_END
No paper in roll paper near end sensor
No paper in roll paper end sensor
A buzzer is on (only for applicable devices)
ASB_BUZZER
ASB_WAIT_REMOVE_LABEL
Waiting for label to be removed (only for applicable devices)
ASB_NO_LABEL No paper in label peeling sensor (only for applicable devices)
ASB_SPOOLER_IS_STOPPED The spooler has stopped
Value of battery
Status of power
Value (battery)
0x30XX
0x31XX
Description
The AC adapter is connected
The AC adapter is connected
Remaining battery
Value (battery)
0xXX36
0xXX35
0xXX34
0xXX33
0xXX32
0xXX31
0xXX30
Description
Battery amount 6
Battery amount 5
Battery amount 4
Battery amount 3
Battery amount 2
Battery amount 1 (Near end)
Battery amount 0 (Real end)
0 is shown when the model doesn't have a battery installed.
Value of printjobid
Value
'...'
'' print job ID
No print job ID
Description
Chapter 4 API Reference
Example
To create and send a print document.
To display the print result in a message box.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printHellowWorld() { var builder = new epson.ePOSBuilder(); builder.addText('Hello, World!\n'); builder.addCut();
var request = builder.toString(); var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer'; var epos = new epson.ePOSPrint(address); epos.onreceive = function (res) {
var success = res.success;
var code = res.code;
var status = res.status;
alert(success);
} epos.send(request);
}
//-->
</script>
4
133
134 onerror event
This property registers the callback function and obtains a communication error event.
Syntax
Function (error)
Parameter of the callback function
Parameters:
Name:
Object type:
error ( See ?Properties of the error object? on page 134.
Communication error information
Object
Properties of the error object
Property
status responseText
Name
HTTP Status
Response text
Object type
Number
String
Example
To create and send a print document.
To display the HTTP status code in a message box when a communication error occurs.
<script type="text/javascript" src=”epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printHellowWorld() { var builder = new epson.ePOSBuilder(); builder.addText('Hello, World!\n'); builder.addCut();
var request = builder.toString(); var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer'; var epos = new epson.ePOSPrint(address); epos.onerror = function (err) {
var status = err.status;
var text = err.responseText;
alert(status);
} epos.send(request);
}
//-->
</script>
Chapter 4 API Reference
onstatuschange event
Registers a callback function to obtain a status change event.
Syntax
Function (status)
Parameter of the callback function
Parameters:
Name:
Object type: status
Status
Number
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onstatuschange = function (status) {
alert(status);
};
epos.open();
//-->
</script>
onbatterystatuschange event
Registers call back function and obtains battery status change event.
Object type
Function (battery)
Parameter of the callback function
Parameters:
Name:
Object type: battery
Batterystatus
Number
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onbatterystatuschange = function (battery) {
alert(battery);
};
epos.open();
//-->
</script>
4
135
ononline event
Registers a callback function to obtain a online event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.ononline = function () {
alert('online');
};
epos.open();
//-->
</script>
onoffline event
Registers a callback function to obtain a offline event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onoffline = function () {
alert('offline');
};
epos.open();
//-->
</script>
136
Chapter 4 API Reference
onpoweroff event
Registers a callback function to obtain a non-response event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onpoweroff = function () {
alert('poweroff');
};
epos.open();
//-->
</script>
oncoverok event
Registers a callback function to obtain a cover close event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.oncoverok = function () {
alert('coverok');
};
epos.open();
//-->
</script>
4
137
oncoveropen event
Registers a callback function to obtain a cover open event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
};
epos.open();
//-->
</script>
onpaperok event
Registers a callback function to obtain a paper remaining event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onpaperok = function () {
alert('paperok');
};
epos.open();
//-->
</script>
138
Chapter 4 API Reference
onpapernearend event
Registers a callback function to obtain a paper near end event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onpapernearend = function () {
alert('papernearend');
};
epos.open();
//-->
</script>
onpaperend event
Registers a callback function to obtain a paper end event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onpaperend = function () {
alert('paperend');
};
epos.open();
//-->
</script>
4
139
ondrawerclosed event
Registers a callback function to obtain a drawer close event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.ondrawerclosed = function () {
alert('drawerclosed');
};
epos.open();
//-->
</script>
ondraweropen event
Registers a callback function to obtain a drawer open event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.ondraweropen = function () {
alert('draweropen');
};
epos.open();
//-->
</script>
140
Chapter 4 API Reference
onbatteryok event
Registers call back function and obtains remaining battery event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onbatteryok = function () {
alert('batteryok');
};
epos.open();
//-->
</script>
onbatterylow event
Registers call back function and obtains no remaining battery event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.ePOSPrint(address);
epos.onbatterylow = function () {
alert('batterylow');
};
epos.open();
//-->
</script>
4
141
142
Chapter 5 Canvas API Reference
Canvas API Reference
This chapter describes the ePOS-Print Canvas API.
Concerning ePOS-Print API, see API Reference (p.51) .
List of ePOS-Print Canvas API functions
The ePOS-Print Canvas API provides the following object:
❏ ePOS-Print Canvas API (window.epson.CanvasPrint) object (
window.epson.CanvasPrint Components
Element
Constructor
CanvasPrint method print open close recover reset
Property
API
address enabled interval status battery timeout halftone brightness cut mode align color feed paper layout drawerOpenLevel
Event onreceive onerror onstatuschange
Description Page
Initializes an ePOS-Print Canvas API object.
Prints an HTML5 Canvas image.
Enables status event operation
Disables status event operation
Recovers from an error
Resets the printer
URL of the printer
Enabling/disabling of status event
Printer status update interval
Status
Battery status
Connection timeout
Raster image halftone processing method
Raster image brightness correction value
Paper cut
Color mode
Position alignment
Printing color
Control of label paper/black mark paper
Type of papers
Paper layout
Signal line status of the drawer that generates ondraweropen and ondrawerclosed events.
Response message receipt event
Communication error event
Status change event
5
143
144
Element
Event
API
Constant onbatterystatuschange onbatteryok onbatterylow ononline onoffline onpoweroff oncoverok oncoveropen onpaperok onpapernearend onpaperend ondrawerclosed ondraweropen
ASB_*
HALFTONE_*
MODE_*
ALIGN_*
COLOR_*
FEED_*
PAPER_*
DRAWER_OPEN_LEVEL_*
Description Page
Battery status change event
Battery OK event
Battery low event
Online event
Offline event
Non-response event
Cover close event
Cover open event
Paper remaining event
Paper near end event
Paper end event
Drawer close event
Drawer open event
Response document status
Halftone type
Color mode
Position alignment
Color specification
Paper feed position of label paper/black mark paper
Type of papers
Signal line status to indicate that the drawer is open
Chapter 5 Canvas API Reference
ePOS-Print Canvas API Object
Prints a print image rendered in HTML5 Canvas and monitors the print result or the communication status.
Constructor
Constructor for an ePOS-Print Canvas API object.
Creates a new ePOS-Print Canvas API object and initializes it.
Syntax
CanvasPrint
(address);
Parameter
address :
( Optional parameter, Object type : String)
Specifies the address property (URL of printer to be used for printing).
The URL is as follows:
http://[ePOS-Print supported TM printer]/cgi-bin/epos/service.cgi?devid=[device
ID of printer to be used for printing]&timeout=[timeout time]
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printCanvas() {
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
}
//-->
</script>
5
145
146 print method
Print the images painted on HTML5 Canvas in accordance with the property settings.
If an HTML5 Canvas image contains images downloaded from different domains, you cannot print the image. In this case, a security error occurs due to violation of the same origin policy of
JavaScript.
Syntax
1
(canvas);
2
(canvas, printjobid);
3
(canvas, cut, mode);
3 is the syntax of compatible version.
Parameter
canvas :
printjobid :
cut :
mode :
( Required parameter, Object type : canvas)
Specify the HTML5 Canvas object to be printed.
Optional parameter, Object type : String)
Specify the print job ID (ePOS‐Print Service Ver.4.1 or later)
You can use from 1 to 30 alphanumeric characters, underscore, hyphen, and period.
( Optional parameter, Object type : Boolean)
Sets whether to cut paper.
true or 1 false or 0 undefined
Setting Description
Cuts the paper after printing
Does not cut the paper after printing
Does not cut the paper after printing
( Optional parameter, Object type : String)
Specifies the color mode.
Setting
MODE_MONO
MODE_GRAY16 undefined
Description
Monochrome (two-tone)
Multiple tones (16-tone)
Monochrome (two-tone)
Exception
Exception
Parameter " ... " is invalid
XMLHttpRequest is not supported
Canvas is not supported
Error
Error
Error
Object type
Chapter 5 Canvas API Reference
Example
To print Canvas(ID=’myCanvas’):
<script type="text/javascript" src=”epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printCanvas() {
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer'; var canvas = document.getElementById('myCanvas'); var epos = new epson.CanvasPrint(address);
epos.onreceive = function (res) { alert(res.success); }; epos.onerror = function (err) { alert(err.status); };
epos.print(canvas);
}
//-->
</script>
5
147
148 open method
Enables status event operation.
Sends the status of the printer specified by the address property using an event.
Updates the status at the interval specified by the interval property.
Syntax open
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function startMonitor() {
epos.open();
} function stopMonitor() {
epos.close();
}
//-->
</script>
close method
Disables status event operation.
Syntax close
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function startMonitor() {
epos.open();
} function stopMonitor() {
epos.close();
}
//-->
</script>
Chapter 5 Canvas API Reference
recover method
Recovers from an error.
Recovers from errors that can be recovered from and clears the buffer.
Syntax recover
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function recover() {
epos.recover();
}
//-->
</script>
reset method
Resets the printer.
Syntax reset
();
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
}; function reset() {
epos.reset();
}
//-->
</script>
5
149
address property
URL of the printer.
Object type
String
Description
The URL of the printer to be used for printing is specified.
The URL is shown as follows:
http://[IP address of ePOS-Print supported TM printer]/cgi-bin/epos/ service.cgi?devid=[device ID of printer to be used for printing]&timeout=[timeout time]
The default value is the address specified by the constructor.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var epos = new epson.CanvasPrint();
epos.address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
//-->
</script>
150 enabled property
Retains the enabled/disabled setting for status event operation.
Object type
Boolean
Description
The enabled/disabled setting for status event operation is retained using a logical value. This is read-only.
The default value is false.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
alert(epos.enabled);
//-->
</script>
Chapter 5 Canvas API Reference
interval property
Specifies the interval of upgrading the status.
Object type
Number
Description
The interval of upgrading the status is specified in milliseconds.
Default value: 3000 (three seconds)
Minimum value: 1000 (one second or longer)
When an invalid value is specified, it is assumed to be 3000.
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.interval = 1000;
epos.oncoveropen = function () { alert('coveropen'); };
epos.open();
//-->
</script>
status property
Hold the TM printer's status.
Object type
Number
Description
This is the status last obtained from the printer. This is read-only.
Default value: 0
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onoffline = function () {
alert(epos.status);
};
epos.open();
//-->
</script>
5
151
152 battery property
Hold the TM printer's battery status.
Object type
Number
Description
Battery status obtained from the last printer status. This is read-only.
Default value: 0
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onbatterylow = function () {
alert(epos.battery);
};
epos.open();
//-->
</script>
timeout property
Specifies connection timeout.
Object type
Number
Description
Specifies connection timeout with ePOS-Print supported printer in milliseconds.
When the transmission of print document by print method times out, onerror even is generated.
Default value: 300000 (5 minutes)
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.timeout = 60000;
epos.onreceive = function (res) { alert(res.success); };
epos.onerror = function (err) { alert(err.status); };
epos.print(canvas);
//-->
</script>
Chapter 5 Canvas API Reference
halftone property
Halftone processing method.
Object type
String
Description
The halftone processing method to be applied to monochrome (two-tone) printing is specified.
The default value is HALFTONE_DITHER.
Constant
HALFTONE_DITHER
HALFTONE_ERROR_DIFFUSION
HALFTONE_THRESHOLD
Description
Dithering, suitable for printing graphics only.
Error diffusion, suitable for printing text and graphics together.
Threshold, suitable for printing text only.
Example
To set the halftone type as error diffusion:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.halftone = epos.HALFTONE_ERROR_DIFFUSION;
epos.print(canvas);
//-->
</script>
5
153
brightness property
Brightness correction value.
Object type
Number
Description
A gamma value in the range 0.1-10.0 is specified for the brightness correction value.
The default value is 1.0.
Example
To set brightness as 2.2:
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.brightness = 2.2;
epos.print(canvas);
//-->
</script>
154 cut property
It sets with or without paper cut.
Object type
Boolean
Description
It specifies with or without paper cut.
Value
true/1 false/0 (Default)
Description
Cut paper after printing
Do not cut paper
Example
It sets paper cut after printing.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.cut = true;
epos.print(canvas);
//-->
</script>
Chapter 5 Canvas API Reference
mode property
It sets the color mode.
Object type
String
Description
It specifies the color mode.
Value
MODE_MONO (Default)
MODE_GRAY16
Description
Monochrome (2-tone)
Multiple tones (16-tone)
Example
Prints with multiple tones.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.mode = epos.MODE_GRAY16;
epos.print(canvas);
//-->
</script>
5
155
156 align property
It sets the position alignment.
Object type
String
Description
It specifies the position alignment.
Value
ALIGN_LEFT (Default)
ALIGN_CENTER
ALIGN_RIGHT
Description
Alignment to the left
Alignment to the center
Alignment to the right
Example
Prints with center alignment.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.align = epos.ALIGN_CENTER;
epos.print(canvas);
//-->
</script>
Chapter 5 Canvas API Reference
color property
It sets printing color.
Object type
String
Description
It specifies printing color.
Value
COLOR_NONE
COLOR_1
COLOR_2
COLOR_3
COLOR_4
No printing
1st color
2nd color
3rd color
4th color
Description
Example
Prints with the 2nd color.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.color = epos.COLOR_2;
epos.print(canvas);
//-->
</script>
5
157
158 feed property
It sets paper feed of label paper/black mark paper.
Object type
String
Description
Paper feed position of label paper/black mark paper.
Value Description
FEED_PEELING
FEED_CUTTING
Feeds to the peeling position.
Feeds to the cutting position.
FEED_CURRENT_TOF (Default) Feeds to the top of the current label.
FEED_NEXT_TOF Feeds to the top of the next label.
Example
After printing a label, it feeds paper to the peeling position.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_LABEL;
epos.feed = epos.FEED_PEELING;
epos.print(canvas);
//-->
</script>
Chapter 5 Canvas API Reference
paper property
It sets paper type.
Object type
String
Description
It specifies paper type.
Value
PAPER_RECEIPT (Default)
PAPER_RECEIPT_BM
PAPER_LABEL
PAPAER_LABEL_BM
Description
Receipt (without black mark)
Receipt (with black mark)
Die-cut label (without black mark)
Die-cut label (with black mark)
Example
Prints a label.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_LABEL;
epos.feed = epos.FEED_PEELING;
epos.print(canvas);
//-->
</script>
5
159
160 layout property
It sets paper layout.
Object type
Object
Description
It specifies paper layout.
Property of layout being setup
Property
width height margin_top margin_bottom offset_cut offset_label
Name Object type
Paper width
Paper height
Top margin
Number
Number
Number
Bottom margin
Cutting position
Number
Number
Bottom position of label Number
Value of width (Object type : Number, When not specified : 580)
Specifies paper width (in units of 0.1 mm). Specifies an integer from 290 to 600. *
Value of height (Object type : Number, When not specified : 0)
Specifies paper height (in units of 0.1 mm).
Valid value range Paper type
Receipt
(without black mark)
0
Description
Setup not necessary
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
0 (auto)
284 to 1550 (manual) *
Distance from the top of black mark to the top of next black mark
Distance from the top of label to the top of next label
Distance from the bottom of black mark to the bottom of next black mark
Value of margin_top (Object type : Number, When not specified : 0)
Specifies top margin (in units of 0.1 mm).
Valid value range Paper type
Receipt
(without black mark)
0
Description
Setup not necessary
Receipt (with black mark)
-150 to 1500 *
0 to 1500 *
Distance from the top of black mark
Distance from the top of label Die-cut label
(without black mark)
Die-cut label
(with black mark)
-15 to 1500 * Distance from the bottom of black mark
Chapter 5 Canvas API Reference
Value of margin_bottom (Object type : Number, When not specified : 0)
Specifies bottom margin (in units of 0.1 mm).
Valid value range Paper type
Receipt
(without black mark)
Receipt (with black mark)
0
0
-15 to 0 *
Description
Setup not necessary
Die-cut label
(without black mark)
Die-cut label
(with black mark)
-15 to 15 *
Distance from the bottom of label (paper feed direction is a positive number)
Distance from the top of black mark (paper feed direction is a positive number)
Value of offset_cut (Object type : Number, When not specified : 0)
Specifies cut position (in units of 0.1 mm).
In case of die cut label paper, it is a distance from the bottom of label.
When a paper has black mark, it is a distance from the beginning of black mark.
Valid value range Paper type
Receipt
(without black mark)
0
Description
Setup not necessary
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
-290 to 50 *
0 to 50 *
0 to 50 *
Distance from the top of black mark to the top of next black mark
Distance from the bottom of label to the cutting position
Distance from the top of black mark to the cutting position
Value of offset_label (Object type : Number, When not specified : 0)
Specifies label bottom position (sd) per 0.1 mm unit.
Valid value range Paper type
Receipt
(without black mark)
Receipt (with black mark)
Die-cut label
(without black mark)
Die-cut label
(with black mark)
0
0
0
0 to 15 *
Description
Setup not necessary
Distance from the top of black mark to the bottom of label
*: Valid value of range is depending on the printer model. For detail, refer to "Appendix - Printer
Specifications".
5
161
162
Layout property positions that can be designated for each type of paper
<without Black Mark> sf
<with Black Mark> sf sb sc
Top position
Cut
Receipt sa
Label
Top position
Cut
Mark sf sa sb se sc sd
Parameter
width height margin_top margin_bottom offset_cut offset_label
sf sb
Bottom edge of print area
se sa sc sc sf
Cut
sb
Top position
Bottom edge of label
Bottom edge of print area
Standard eject
se sd sa sc
Chapter 5 Canvas API Reference
Example
To set 58 mm receipt (without black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_RECEIPT;
epos.layout = { width: 580 };
epos.cut = true;
epos.print(canvas);
//-->
</script>
To set 58 mm receipt (with black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_RECEIPT_BM;
epos.layout = { width: 580, height: 0, margin_top:15, offset_cut: 0 };
epos.cut = true;
epos.print(canvas);
//-->
</script>
To set 58 mm die-cut label (without black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_LABEL;
epos.layout = { width: 580, height: 0, margin_top: 15, margin_bottom: -15, offset_cut: 25 };
epos.cut = true;
epos.print(canvas);
//-->
</script>
5
163
To set 58 mm die-cut label (with black mark):
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var canvas = document.getElementById('myCanvas');
var epos = new epson.CanvasPrint(address);
epos.paper = epos.PAPER_LABEL_BM;
epos.layout = { width: 580, height: 0, margin_top: 15, margin_bottom: -15 offset_cut: 25, offset_label: 15 };
epos.cut = true;
epos.print(canvas);
//-->
</script>
164
Chapter 5 Canvas API Reference
drawerOpenLevel property
Using Low or High, specify the signal line status.
Object type
Number
Description
Using Low or High, specify the signal line status of the drawer that generates the ondraweropen and ondrawerclosed events.
Setting
DRAWER_OPEN_LEVEL_LOW
(Default)
DRAWER_OPEN_LEVEL_HIGH
Signal line status
HIGH -> LOW
LOW -> HIGH
HIGH -> LOW
LOW -> HIGH
Description
ondraweropen event is generates.
ondrawerclosed event is generates.
ondrawerclosed event is generates.
ondraweropen event is generates.
Example
epos.drawerOpenLevel = epos.DRAWER_OPEN_LEVEL_HIGH;
5
165
166 onreceive event
This property registers the callback function and obtains a response message receipt event.
Syntax
Function (response)
Parameter of the callback function
Parameter:
Name:
Object type:
response ( See ʺProperties of the response objectʺ on page 166.
)
Response message
Object
Properties of the response object
Parameter
success (
)
status (
battery (
)
Value of success
Value
true or 1 false or 0
Value of code
Value
'EPTR_AUTOMATICAL'
'EPTR_COVER_OPEN'
'EPTR_CUTTER'
'EPTR_MECHANICAL'
'EPTR_REC_EMPTY'
'EPTR_UNRECOVERABLE'
'SchemaError'
'DeviceNotFound'
'PrintSystemError'
'EX_BADPORT'
'EX_TIMEOUT'
Name
Print result
Error code
Status
Battery status
Print job ID
Printing succeeded.
Printing failed.
Boolean
String
Number
Number
String
Object type
Description
Description
An automatically recoverable error occurred
A cover open error occurred
An autocutter error occurred
A mechanical error occurred
No paper in roll paper end sensor
An unrecoverable error occurred
The request document contains a syntax error
The printer with the specified device ID does not exist
An error occurred on the printing system
An error was detected on the communication port
A print timeout occurred
Chapter 5 Canvas API Reference
Value of Status
Constant (status) Description
ASB_NO_RESPONSE
ASB_PRINT_SUCCESS
ASB_DRAWER_KICK
ASB_BATTERY_OFFLINE
ASB_OFF_LINE
ASB_COVER_OPEN
ASB_PAPER_FEED
ASB_WAIT_ON_LINE
ASB_PANEL_SWITCH
ASB_MECHANICAL_ERR
ASB_AUTOCUTTER_ERR
ASB_UNRECOVER_ERR
No response from the TM printer
Printing is successfully completed
Status of the 3rd pin of the drawer kick-out connector = "H"
Off line status from remaining battery
(only for applicable devices)
Offline
The cover is open
Paper is being fed by a paper feed switch operation
Waiting to be brought back online
The paper feed switch is being pressed (ON)
A mechanical error occurred
An autocutter error occurred
An unrecoverable error occurred
ASB_AUTORECOVER_ERR
ASB_RECEIPT_NEAR_END
ASB_RECEIPT_END
ASB_BUZZER
An automatically recoverable error occurred
No paper in roll paper near end sensor
No paper in roll paper end sensor
A buzzer is on (only for applicable devices)
ASB_WAIT_REMOVE_LABEL Waiting period for removal of label (only for applicable devices)
ASB_NO_LABEL No paper in label peeling sensor (only for applicable devices)
ASB_SPOOLER_IS_STOPPED The spooler has stopped (Not used)
Value of battery
Status of power
Value (battery)
0x30XX
0x31XX
Description
AC adapter is connected
AC adapter is not connected
Remaining battery
Value (battery)
0xXX36
0xXX35
0xXX34
0xXX33
0xXX32
0xXX31
0xXX30
Description
Remaining battery 6
Remaining battery 5
Remaining battery 4
Remaining battery 3
Remaining battery 2
Remaining battery 1 (Near end)
Remaining battery 0 (Real end)
0 is shown when the model doesn't have a battery installed.
5
Value of printjobid
Value
'...'
Description
Print job ID
(No print job ID for null character strings)
167
168
Example
To print Canvas(ID=myCanvas):
To display the print result in a message box.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printCanvas() {
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer'; var canvas = document.getElementById('myCanvas'); var epos = new epson.CanvasPrint(address); epos.onreceive = function (res) {
var success = res.success;
var code = res.code;
var status = res.status;
alert(success);
}; epos.print(canvas);
}
//-->
</script>
Chapter 5 Canvas API Reference
onerror event
This property registers the callback function and obtains a communication error event.
Syntax
Function (error)
Parameter of the callback function
Parameter:
Name:
Object type:
error ( See ʺProperties of the error objectʺ on page 169.
Communication error information
Object
Properties of the error object
property
status responseText
Name
HTTP status
Responce text
Object type
Number
String
Example
To print Canvas(ID=myCanvas):
To display the HTTP status code in a message box when a communication error occurs.
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!-function printCanvas() {
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer'; var canvas = document.getElementById('myCanvas'); var epos = new epson.CanvasPrint(address); epos.onerror = function (err) {
var status = err.status;
var text = err.responseText;
alert(status);
}; epos.print(canvas);
}
//-->
</script>
5
169
170 onstatuschange event
Registers a callback function to obtain a status change event.
Syntax
Function (status)
Parameter of the callback function
Parameters:
Name:
Object type: status
Status
Number
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onstatuschange = function (status) {
alert(status);
};
epos.open();
//-->
</script>
onbatterystatuschange event
Registers call back function and obtains battery status change event.
Syntax
Function (battery)
Parameter of the callback function
Parameters:
Name:
Object type: battery
Battery status
Number
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onbatterystatuschange = function (battery) {
alert(battery);
};
epos.open();
//-->
</script>
Chapter 5 Canvas API Reference
onbatteryok event
Registers call back function and obtains remaining battery event.
Syntax
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onbatteryok = function () {
alert('batteryok’);
};
epos.open();
//-->
</script>
onbatterylow event
Registers call back function and obtains no remaining battery event.
Syntax
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onbatterylow = function () {
alert('batterylow’);
};
epos.open();
//-->
</script>
5
171
ononline event
Registers a callback function to obtain a online event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.ononline = function () {
alert('online');
};
epos.open();
//-->
</script>
onoffline event
Registers a callback function to obtain a offline event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onoffline = function () {
alert('offline');
};
epos.open();
//-->
</script>
172
Chapter 5 Canvas API Reference
onpoweroff event
Registers a callback function to obtain a non-response event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onpoweroff = function () {
alert('poweroff');
};
epos.open();
//-->
</script>
oncoverok event
Registers a callback function to obtain a cover close event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoverok = function () {
alert('coverok');
};
epos.open();
//-->
</script>
5
173
174 oncoveropen event
Registers a callback function to obtain a cover open event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.oncoveropen = function () {
alert('coveropen');
};
epos.open();
//-->
</script>
onpaperok event
Registers a callback function to obtain a paper remaining event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onpaperok = function () {
alert('paperok');
};
epos.open();
//-->
</script>
Chapter 5 Canvas API Reference
onpapernearend event
Registers a callback function to obtain a paper near end event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onpapernearend = function () {
alert('papernearend');
};
epos.open();
//-->
</script>
onpaperend event
Registers a callback function to obtain a paper end event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.onpaperend = function () {
alert('paperend');
};
epos.open();
//-->
</script>
5
175
176 ondrawerclosed event
Registers a callback function to obtain a drawer close event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.ondrawerclosed = function () {
alert('drawerclosed');
};
epos.open();
//-->
</script>
ondraweropen event
Registers a callback function to obtain a drawer open event.
Object type
Function ()
Example
<script type="text/javascript" src="epos-print-x.x.x.js"></script>
<script type="text/javascript">
<!--
var address = 'http://192.168.192.168/cgi-bin/epos/service.cgi?devid=local_printer';
var epos = new epson.CanvasPrint(address);
epos.ondraweropen = function () {
alert('draweropen');
};
epos.open();
//-->
</script>
Download
Advertisement
Key features
Standard and Page print modes
Text printing with various font settings
Image printing from HTML5 Canvas
Barcode printing
2D-code printing
Drawer kick-out control
Buzzer control
Paper cut control
Status event notification
Frequently asked questions
There are two print modes: standard mode and page mode. In standard mode, characters are printed line by line, while in page mode, you set a print area, lay out data in it, and print the data in a batch operation.
You can use the addText method to print text. You can also set various font settings, including language, font type, size, style, and color.
Yes, you can print images using the addImage method. The API supports printing raster images obtained by rendering an image in HTML5 Canvas.
You can use the addPulse method to control the drawer kick-out. You can specify the pulse length and connector.
The status event notification feature allows you to check the status of the TM printer without printing. You can use the onreceive property to receive the print result and printer status.