POSPrinter provides a fluent style api for preparing ESC/POS data. Supported commands depend on printer model.

The class uses ESC/P sequences. ESC/P, short for Epson Standard Code for Printers and sometimes styled Escape/P, is a printer control language developed by Epson to control computer printers. It was mainly used in dot matrix printers and some inkjet printers, and is still widely used in many receipt thermal printers.

# 1 POS printer

The POSPrinter provides a fluent api to compose ESC commands for POS printers. The following example shows a variety of commands including barcode generation.

Copy
<script>

var pos = new Ax.pos.POSPrinter()
.build()
.setCharacterCodeTable(Ax.pos.POSPrinter.CharacterCodeTable.PC437)

// ====================================================
// Center and increase character size
// ====================================================
.setAlign("CENTER")
.setCharacterSize(Ax.pos.POSPrinter.Width.X3, Ax.pos.POSPrinter.Height.X3)

// ====================================================
// ====================================================

.setUnderline(Ax.pos.POSPrinter.Underline.TWO_DOT)
.setEmphasize(true)
.text("STORE AEO")
.printAndFeedLine()
.setEmphasize(false)
.setUnderline(Ax.pos.POSPrinter.Underline.CANCEL)
.text("Barcelona")
.printAndFeedLine()
.printAndFeedLines(2)

// ====================================================
// Reduce character size
// ====================================================
.setCharacterSize(Ax.pos.POSPrinter.Width.X1, Ax.pos.POSPrinter.Height.X1)
.setAlign("LEFT")
.text("NIF: A282382832").printAndFeedLine()
.text("01-09-2019 20:00").printAndFeedLine()
.printAndFeedLine()

// ====================================================
// BARCODES
// ====================================================
.write(new Ax.pos.POSBarcode("UPCA")    .setAlign("CENTER").setTextPosition("above").print("12345678901"))
.write(new Ax.pos.POSBarcode("UPCA_B")  .setAlign("CENTER").setTextPosition("none").print("12345678901"))
.write(new Ax.pos.POSBarcode("UPCE_A")  .setAlign("CENTER").print("230404"))
.write(new Ax.pos.POSBarcode("UPCE_B")  .setAlign("CENTER").print("230404"))
.write(new Ax.pos.POSBarcode("EAN13_A") .setAlign("CENTER").print("123456789012"))
.write(new Ax.pos.POSBarcode("EAN13_B") .setAlign("CENTER").print("123456789012"))
.write(new Ax.pos.POSBarcode("EAN8_A")  .setAlign("CENTER").print("12345678"))
.write(new Ax.pos.POSBarcode("EAN8_B")  .setAlign("CENTER").print("12345678"))
.write(new Ax.pos.POSBarcode("CODE39_A").setAlign("CENTER").print("DR2039"))
.write(new Ax.pos.POSBarcode("CODE39_B").setAlign("CENTER").print("DR2039"))
.write(new Ax.pos.POSBarcode("CODE93")  .setAlign("CENTER").print("DR2039"))
.write(new Ax.pos.POSBarcode("CODE128") .setAlign("CENTER").setTextPosition("aboveandbelow").print("{A81007123452112345678"))
.write(new Ax.pos.POSQRCode()           .setAlign("CENTER").setSize(3).print("Please don’t try to scan this one"))
.write(new Ax.pos.POSPDF417()           .setAlign("CENTER").setSize(3, 3).print("ABCabc123"))

// ====================================================
// END + CUT PAPER
// ====================================================
.printAndFeedLines(5)
.cut(Ax.pos.POSPrinter.CutA.PARTIAL);

// ====================================================
// Show bytes to be sent
// ====================================================
console.log(pos.getBytes());

// ====================================================
// Open a LPR printer
// ====================================================
var lpr = new Ax.net.LPRClient("192.168.12.125");
// No more than 5 seconds before timeout
lpr.setTimeout(5000);

// ====================================================
// Send a job to the printer
// ====================================================
var job = lpr.print(pos.getBytes());
console.log("PRINT ID:" + job);
console.log(lpr.getQueueState());

</script>

# 2 Write Commands

 text(String text) Sends a string to the printer. bytes(byte[] bytes) Sends a raw byte array to the printer.

# 3 Print Commands

 printAndFeedLine() Prints the data in the print buffer and feeds one line, based on the current line spacing. The amount of paper fed per line is based on the value set using the line spacing command (ESC 2 or ESC 3). After printing, the print position is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". When this command is processed in Page mode, only the print position moves, and the printer does not perform actual printing. printAndReturnToStandardMode() In Page mode, prints the data in the print buffer collectively. This command is enabled only in Page mode. Page mode can be selected by ESC L. After printing, the printer does not clear the buffered data, the print position, or values set by other commands. The printer returns to Standard mode with FF, ESC S, and ESC @. When it returns to Standard mode by ESC @, all settings are canceled. This command is used when the data in Page mode is printed repeatedly. printAndCarriageReturn() Executes one of the following operations (Alignment, Auto Line Feed): Horizontal, Enabled - Executes printing and one line feed as LF Horizontal, Disabled - This command is ignored. Vertical, Enabled - Executes printing and one line feed as LF Vertical, Disabled - In Standard mode, prints the data in the print buffer and moves the print position to the beginning of the print line. In Page mode, moves the print position to the beginning of the print line. Notes: With a serial interface, the command performs as if auto line feed is disabled. Enabling or disabling the auto line feed can be selected by the DIP switch or the memory switch. Memory switch can be changed with GS ( E After printing, the print position is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". When this command is processed in Page mode, only the print position moves, and the printer does not perform actual printing. printInPageMode() In Page mode, prints all the data in the print buffer collectively and switches from Page mode to Standard mode. This command is enabled only in Page mode. See FF (in Standard mode) to use this command in Standard mode. Page mode can be selected by ESC L. The data is deleted in the print area after being printed. This command returns the values set by ESC W to the default values. The value set by ESC T is maintained. After printing, the printer returns to Standard mode and moves the print position to left side of the printable area. Also, the printer is in the status "beginning of the line". printAndFeedPaper(int n) Prints the data in the print buffer and feeds the paper [n × (vertical or horizontal motion unit)]. When Standard mode is selected, the vertical motion unit is used. When Page mode is selected, the vertical or horizontal motion unit is used for the print direction set by ESC T. When the starting position is set to the upper left or lower right of the print area using ESC T, the vertical motion unit is used. When the starting position is set to the upper right or lower left of the print area using ESC T, the horizontal motion unit is used. The maximum paper feed amount depends on the printer model. If specified over the maximum amount, the maximum paper feed is executed. After printing, the print postion is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". When this command is processed in Page mode, only the print position moves; the printer does not perform actual printing. This command is used to temporarily feed a specific length without changing the line spacing set by other commands. printAndReverseFeed(int n) Prints the data in the print buffer and feeds the paper n × (vertical or horizontal motion unit) in the reverse direction. When Standard mode is selected, the vertical motion unit is used. When Page mode is selected, the vertical or horizontal motion unit is used for the print direction set by ESC T. When the starting position is set to the upper left or lower right of the print area using ESC T, the vertical motion unit is used. When this command is processed in Page mode, only the print position moves; the printer does not perform actual printing. After printing, the print postion is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". The maximum paper feed amount depends on the printer model. If specified over the maximum amount, the reverse feed is not executed although the print is executed. This command is used to temporarily feed a specific length without changing the line spacing set by other commands. Some printers execute a little forward paper feed after reverse feed, from a restriction of the printer mechanism. printAndFeedLines(int n) Prints the data in the print buffer and feeds n lines. The amount of paper fed per line is based on the value set using the line spacing command (ESC 2 or ESC 3). The maximum paper feed amount depends on the printer model. If specified over the maximum amount, the maximum paper feed is executed. After printing, the print postion is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". When this command is processed in Page mode, only the print position moves, and the printer does not perform actual printing. This command is used to temporarily feed a specific line without changing the line spacing set by other commands. printAndReverseFeedLines(int n) Prints the data in the print buffer and feeds n lines in the reverse direction. The amount of paper fed per line is based on the value set using the line spacing command (ESC 2 or ESC 3). The maximum paper feed amount depends on the printer model. If specified over the maximum amount, the reverse feed is not executed although the print is executed. After printing, the print postion is moved to left side of the printable area. Also, the printer is in the status "beginning of the line". When this command is processed in Page mode, only the print position moves, and the printer does not perform actual printing. This command is used to temporarily feed a specific line without changing the line spacing set by other commands. Some printers execute a little forward paper feed after reverse feed, from a restriction of the printer mechanism.

# 4 Line Spacing Commands

 setDefaultLineSpacing() Sets the line spacing to the "default line spacing". The line spacing can be set independently in Standard mode and in Page mode. In Standard mode this command sets the line spacing of Standard mode. In Page mode this command sets the line spacing of page mode. Selected line spacing is effective until ESC 3 is executed, ESC @ is executed, the printer is reset, or the power is turned off. setLineSpacing(int n) Sets the line spacing to n × (vertical or horizontal motion unit). The maximum line spacing is 1016 mm {40 inches}. However, it may be smaller depending on models. If the specified amount exceeds the maximum line spacing, the line spacing is automatically set to the maximum. When Standard mode is selected, the vertical motion unit is used. When Page mode is selected, the vertical or horizontal motion unit is used for the print direction set by ESC T. When the starting position is set to the upper left or lower right of the print area using ESC T, the vertical motion unit is used. When the starting position is set to the upper right or lower left of the print area using ESC T, the horizontal motion unit is used. The line spacing can be set independently in Standard mode and in Page mode. In Standard mode this command sets the line spacing of Standard mode. In Page mode this command sets the line spacing of page mode. When the motion unit is changed after the line spacing is set, the line spacing setting does not change. Selected line spacing is effective until ESC 2 is executed, ESC @ is executed, the printer is reset, or the power is turned off.

# 7 Mechanism Control Commands

 returnHome() Moves the print head to the standby position. The standby position is different, depending on the printer model. The command rechecks the standby position; therefore, the print position might be shifted before and after checking the standby position. setUnidirectionalPrint(boolean enabled) Turns unidirectional print mode on or off. This mode can be set independently in Standard mode and in Page mode. When this command is used in Standard mode, the printer sets the mode for Standard mode. When this command is used in Page mode, the printer sets the mode for page mode. When unidirectional print mode is turned off, bidirectional print mode is automatically turned on. When Page mode is selected, the printer performs unidirectional printing for all data that is to be collectively printed using FF or ESC FF. Unidirectional print mode can be turned on when printing double-height characters or graphics or bit image or two-dimensional code to ensure that the top and bottom of the printing patterns are aligned. Settings of this command are effective until ESC @ is executed, the printer is reset, or the power is turned off. cut(CutA cut) Executes paper cut. When using this command, note that there is a gap between the cutting position and the print position. cutWithFeed(CutB cut, int n) Feeds paper to [cutting position + (n × vertical motion unit)] and executes paper cut. Printers without an auto-cutter only feed the paper for specified amount. cutPosition(CutC cut, int n) Preset [cutting position + (n × vertical motion unit)] to the paper cutting position, and executes paper cut when it reaches the autocutter position after printing and feeding The preset cutting position is cleared if any of the following cases is performed. Execution of ESC @ Execution of commands that perform a software reset Power off or hardware reset Paper feed by pressing paper feed button Execution of buffer clear commands The paper cut involves a stop of printing. This might affect the print quality. The function makes it possible to save paper by reducing the top margin for continuous printing. cutWithFeedAndReturnStart(CutD cut, int n) Feeds paper to [cutting position + (n × vertical motion unit)] and executes paper cut, then moves paper to the print start position by reverse feeding. The function makes it possible to save paper by reducing the top margin for continuous printing. The top margin of the print start position is different depending on the printers.

# 8 Panel Button Commands

 setPanelButtons(boolean enabled) Enables or disables the panel buttons. If panel buttons are enabled, the function of the panel button, such as feeding, will be executed when the panel button is turned on. If panel buttons are disabled, the function of the panel button will not be executed even if pressed the button. To prevent problems caused by accidentally pressing the buttons, use this command to disable the buttons. Setting of this command is effective until ESC @ is executed, the printer is reset, or the power is turned off. When the printer cover is open, there are buttons that are always enabled or disabled regardless of this command. The buttons are different, depending on the printer model. Even if the panel buttons are disabled by this command, paper feed button will be enabled temporarily while printer is waiting for the buttons to be pressed. The following are some examples of the case. When a new roll of paper is installed in the TM-U230 When waiting for an online recovery for the TM-L90 with Peeler When the printer is waiting for the button to be pressed while GS ^ is executed

# 9 Kanji Commands

 setKanjiPrintMode(boolean underlined, boolean doubleWidth, boolean doubleHeight) Selects the character styles (double-height, double-width, and Kanji-underlined) together for multi-byte code character. Settings of this command affect multilingual characters and user-defined characters. Settings of this command are effective until any of the following commands are executed, ESC @ is executed, the printer is, or the power is turned off. Character size (bits 2 and 3): FS W, GS ! Underline (bit 7): FS - When a double-height mode is specified, a character is enlarged based on a baseline of the character. When a double-width mode is specified, a character is enlarged based on the left side of the character. When both double-width and double-height modes are specified, quadruple-size characters are printed. When double-height mode is selected in Standard mode, a character is enlarged in the paper feed direction and when double-width mode is selected, a character is enlarged in the direction which is perpendicular to the paper feed direction. Therefore, when 90° clockwise-rotation is selected, the relationship between directions of enlargement of double-height and double-width is opposite from normal direction. When double-height mode is selected in Page mode, height size is enlarged and when double-width mode is selected in Page mode, width size is enlarged. When Kanji underline mode is specified, the width of the underline set by FS - is added. Even if the character size is changed, the width is not changed. The underline has the same color as the characters. The color can be selected by Function 48 of GS ( N. Even if Kanji underline mode is specified, 90° clockwise-rotated characters, white/black reverse characters, and spaces skipped by HT, ESC $, or ESC \ are not underlined. setKanjiCharacterMode() Selects Kanji character mode. This command can be used only for the Japanese, Simplified Chinese, and Traditional Chinese models. Settings of this command are effective until FS . is executed, ESC @ is executed, the printer is reset, or the power is turned off. Notes for Japanese models: Settings of this command affect processing of a character code only when JIS code system is selected by FS C. If Kanji mode is specified when JIS code system is selected, the printer processes a character code as a 2-byte code. Kanji codes are processed in order of the first byte then the second byte. Kanji mode is canceled at default. Notes for Simplified Chinese models: When Kanji mode is selected, the printer processes a character code that corresponds to the first byte of Kanji code, and then processes consecutive byte(s) as the second byte ( – the fourth byte) of Kanji code. Therefore, when Kanji code is specified, an ASCII code character that corresponds to the first byte of Kanji code cannot be printed. Kanji mode is selected at default. Notes for Traditional Chinese models: When Kanji mode is selected, the printer processes a character code that corresponds to the first byte of Kanji code, and then processes a consecutive byte as the second byte of Kanji code. Therefore, when Kanji code is specified, an ASCII code character that corresponds to the first byte of Kanji code cannot be printed. Kanji mode is selected at default. setKanjiUnderline(Underline underline) Turns on or off underline mode for multi-byte code character (Kanji-underline). Settings of this command affect multilingual characters and user-defined characters. The underline has the same color as the characters. The color can be selected by Function 48 of GS ( N. Even if Kanji underline mode is specified, 90° clockwise-rotation characters, white/black reverse characters, and spaces skipped by HT, ESC$, or ESC \ are not underlined. When a character size is changed, an underline width is not changed. When underline mode is canceled, the following characters are not underlined; however, an underline width set right before the mode is canceled remains. Settings of this command are effective until FS ! is executed, ESC @ is executed, the printer is reset, or the power is turned off. Some printer models support Kanji underline mode with 2-dot width. cancelKanjiCharacterMode() Cancels Kanji character mode. This command can be used only for the Japanese, Simplified Chinese, and Traditional Chinese models. Settings of this command are effective until FS & is executed, ESC @ is executed, the printer is reset, or the power is turned off. Notes for Japanese models: Settings of this command affect character code processing only when JIS code system is selected by FS C. When JIS code system is selected, if Kanji mode is canceled, the printer processes a character code as a 1-byte code of alphanumeric Katakana characters. Kanji mode is canceled at default. Notes for Simplified Chinese models: If Kanji mode is canceled, the printer processes a character code as a 1-byte code of alphanumeric Katakana characters. Kanji mode is selected at default. Notes for Traditional Chinese models: If Kanji mode is canceled, the printer processes a character code as a 1-byte code of alphanumeric Katakana characters. Kanji mode is selected at default. setKanjiCodeSystem(Kanji kanji) Selects a Kanji character code system for the Japanese model. This command is effective only with Japanese model. When JIS code system is selected, Kanji mode should be specified by FS & to print Kanji characters. When SHIFT JIS code system is selected, if the printer processes a character code that corresponds to the first byte of the Kanji code, the printer processes a consecutive byte as the second byte of the Kanji code. Therefore, when this code system is selected, ASCII code that corresponds to the first byte of the Kanji code cannot be printed. Kanji code processes the first byte and the second byte in order. The command is effective until ESC @ is executed, the printer is reset, or the power is turned off. setKanjiCharacterSpacing(int n1, int n2) Sets left- and right-side spacing of the multi-byte code character n1 and n2, respectively. Sets the left-side character spacing to [n1 × horizontal or vertical motion units]. Sets the right-side character spacing to [n2 × horizontal or vertical motion units]. Notes: Settings of this command affect multilingual characters and user-defined characters. When a character size is set to N times as large as a normal size, both right- and left-side character spacings are also set to N times as large as a normal size. In Standard mode, the horizontal motion unit (perpendicular to the paper feed direction) is used. in Page mode, the horizontal or vertical motion unit differs, depending on the starting position set by ESC T. When the starting position is set to the upper left or lower right, the horizontal motion unit (perpendicular to the paper feed direction) is used. When the starting position is set to the upper right or lower left, the vertical motion unit (paper feed direction) is used. Different character spacing can be set for Standard mode and page mode. When this command is set in Standard mode, character spacing for multilingual (except Thai) characters printed in Standard mode is set. When this command is set in Page mode, character spacing for multilingual (except Thai) characters printed in Page mode is set. If the horizontal or vertical motion unit is changed after setting the character spacing, the spacing between the characters is not changed. The character spacing is effective until ESC @ is executed, the printer is reset, or the power is turned off. This command is used to change spacing between characters. setKanjiQuadrupleSize(boolean enabled) Turns quadruple-size mode on or off for multi-byte code character. Settings of this command affect multilingual characters and user-defined characters. When a double-height mode is specified, a character is enlarged based on a baseline of the character and when a double-width mode is specified, a character is enlarged based on the left side of the character. Settings of this command are effective until FS ! is executed, GS ! is executed, ESC @ is executed, the printer is reset, or the power is turned off.

# 10 Miscellaneous Commands

initialize()

Clears the data in the print buffer and resets the printer modes to the modes that were in effect when the power was turned on.

• Any macro definitions are not cleared.
• Offline response selection is not cleared.
• Contents of user NV memory are not cleared.
• NV graphics (NV bit image) and NV user memory are not cleared.
• The maintenance counter value is not affected by this command.
• Software setting values are not cleared.

Notes:

• The DIP switch settings are not checked again.
• The data in the receive buffer is not cleared.
• When this command is processed in Page mode, the printer deletes the data in the print areas, initializes all settings, and selects Standard mode.
• This command can cancel all the settings, such as print mode and line feed, at the same time.
• The command execution moves the print position to left side of the printable area. Also, the printer is in the status "beginning of the line".

sendRealTimeRequest(RealTimeRequest realTimeRequest)

Responds to a request in real time from the host computer.

• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• DLE ENQ 0 can be used in the following online recovery waiting status.
• Online recovery after roll paper insertion in TM-U230 (See GS z 0)
• Online recovery for the TM-L90 with Peeler (See GS z 0 (Peeler)).
• Status waiting for the button to be pressed, while GS ^ is executed.
• DLE ENQ 1 or DLE ENQ 2 is enabled only when a recoverable error occurs, with the exception of an automatically recoverable error. When a recoverable error occurs, after removing the cause of the error, the printer can recover from the error by transmitting this command without the printer being turned off. Errors recoverable by this command depend on the printer model.
• in Page mode, if the printer recovers from a recoverable error by using DLE ENQ 2, the printer returns to Standard mode after clearing the data in receive and print buffers and changing the values set by ESC W to the default values.
• After processing DLE ENQ 2, the print position is moved to left side of the printable area. Also, the printer is in the status "beginning of the line".

sendRealTimeRequestPulse(Pin pin, PulseTime pulseTime)

Outputs the pulse specified by t to connector pin. The pulse ON time is [t × 100 ms] and the OFF time is [t × 100 ms]

• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• This command is ignored in the following states:
• In error status
• When a pulse is being output to the drawer kick-out connector
• During transmission of block data (Header – NUL)
• When this command is disabled by GS ( D
• It is not possible to output the pulses to the drawer kick-out connector pin 2 and 5 at the same time.

sendRealTimeRequestPowerOff()

Executes the printer power-off sequence and transmits the power-off notice.

• Saving the maintenance counter values
• Busy controlling for interface
• Changing to waiting state of mechanism

Notes:

• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• This command can be used after enabling real time command processing with GS ( D.
• All information and data stored in RAM will be deleted by processing this command.
• When the printer has executed setup of power off processing, the printer transmits the power-off notice as shown below to the host.
 Power-off notice Hex Decimal Number of bytes Header 3Bh 59 1 byte Identifier 30h 48 1 byte NUL 00h 00 1 byte
• Maintenance counter values are maintained by executing this command; therefore the maintenance counter values will be more accurate if the user uses this command before turning off the power switch.
• The power-off notice can be differentiated from other transmission data according to specific data of the transmission data block. When the header transmitted from the printer is [hex = 3Bh / decimal = 59], treat NUL [hex = 00h / decimal = 0] as a data group and identify it according to the combination of the header and the identifier.

sendRealTimeRequestBuzzer(int a, int n, int r, int t1, int t2)

Sounds the buzzer with a sound pattern specified by a the number of times specified by r. a, n, r, t1, t2: different depending on the printers.

• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• This command can be used after enabling real time command processing with GS ( D.
• The function of not sounding the buzzer affects autonomous buzzer sound (errors, paper-end) and buzzer sound with ESC ( A <Function 97>, buzzer sound during cutting, buzzer sound by generating the specified pulse.

sendRealTimeRequestStatus(Status status)

Transmits specified status in real-time as follows.

• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• The status or response format is the same as the format of the related command in the table above. See the description of the related command corresponding to m.
• Battery status differs depending on printer model.
• This command is not affected the setting of the corresponding ASB or response. This command transmits the ASB or response only once, even if it is disabled by the related command.
• This command doesn't affect the setting of the corresponding ASB or response.

sendRealTimeRequestClearBuffers()

Clears all data stored in the receive buffer and the print buffer and transmits Clear response.

• Do not use this command in a system in which the printer is used with the OPOS driver and Java POS driver that are provided by Seiko Epson Corporation.
• This is a Real-time command. Refer to Notes of Real-time commands for usage note.
• When this command is transmitted, do not transmit data that follows until the Clear responseis received.
• If this command is sent while another command is processing, processing of the other command is canceled.
• Exmaple: If this command is sent while NV graphics is defined, the definition will be canceled.
• If this command is processed in Page mode, the printer returns to Standard mode. The setting of ESC W is changed to the default.
• This command does not change or initialize settings of other commands (except for ESC W with Page mode selected).
• The command execution moves the print position to left side of the printable area.
• If this command is executed when a recoverable error has occurred, the printer recovers from the error. This is the same function as DLE ENQ 2.
• When buffer clear processing is finished, the printer transmits the Clear response as shown below.
 Clear Response Hex Decimal Number of bytes Header 37h 55 1 byte Identifier 25h 37 1 byte NUL 00h 00 1 byte

setPeripheralDevice(int n)

Set peripheral device. n is different depending on printer

• When the printer is disabled, it ignores all received data and commands with the exception of ESC = and real-time commands.
• If ASB is enabled when the printer is disabled by this command, the printer transmits the ASB status message whenever the status changes. See the description of GS a for ASB function.
• Settings of this command are effective until ESC @ is executed, the printer is reset, or the power is turned off.
• The default value when the power supply is turned on and when ESC @ is executed might be different.

setPageMode()

Switches from Standard mode to Page Mode.

• This command is enabled only in Page mode. Page mode can be selected by ESC L.
• When this command is executed, data in all the print areas is cleared, the print area set by ESC W returns to the default value, but the value set by ESC T is maintained.
• The following commands switch the settings for Standard mode because these commands can be set independently in Standard mode and in Page mode:
• ESC SP, ESC 2, ESC 3, ESC U, FS S
• In Standard mode, the following commands are ignored.
• CAN, ESC FF, GS $, GS ( Q, GS \ • The settings of the following commands do not affect printing in Standard mode. • ESC T, ESC W, GS ( P • Standard mode is selected as the default. setStandardMode() Switches from Page Mode to Standard Mode. • This command is enabled only in Page mode. Page mode can be selected by ESC L. • When this command is executed, data in all the print areas is cleared, the print area set by ESC W returns to the default value, but the value set by ESC T is maintained. • The following commands switch the settings for Standard mode because these commands can be set independently in Standard mode and in Page mode: • ESC SP, ESC 2, ESC 3, ESC U, FS S • In Standard mode, the following commands are ignored. • CAN, ESC FF, GS$, GS ( Q, GS \
• The settings of the following commands do not affect printing in Standard mode.
• ESC T, ESC W, GS ( P
• Standard mode is selected as the default.

generatePulse(Pin pin, int t1, int t2)

Outputs the pulse specified by t1 and t2 to the specified connector pin. The pulse for ON time is (t1 × 2 msec) and for OFF time is (t2 × 2 msec).

• If t2 < t1, the OFF time is equal to the ON time.
• It is not possible to output the pulses to the drawer kick-out connector pin 2 and 5 at the same time.

setMotionUnits(int x, int y)

Sets the horizontal and vertical motion units to approximately 25.4/x mm {1/x"} and approximately 25.4/y mm {1/y"}, respectively.

• When x = 0, the default value of the horizontal motion unit is used.
• When y = 0, the default value of the vertical motion unit is used.

Notes:

• The horizontal and vertical motion units indicate the minimum pitch used for calculating the values of related commands.
• The horizontal direction is perpendicular to the paper feed direction and the vertical direction is the paper feed direction.
• In Standard mode, the following commands use x or y.
• Commands using x: ESC SP, ESC $, ESC \, FS S, GS ( P, GS L, and GS W • Commands using y: ESC 3, ESC J, ESC K, GS ( P, and GS V • in Page mode, the following commands use x or y, when the starting position is set to the upper left or lower right of the print area using ESC T. • Commands using x: ESC SP, ESC$, ESC W, ESC \, GS ( Q, and FS S
• Commands using y: ESC 3, ESC J, ESC K, ESC W, GS $, GS V, GS ( Q, and GS \ • in Page mode, the following commands use x or y, when the starting position is set to the upper right or lower left of the print area using ESC T. • Commands using x: ESC 3, ESC J, ESC K, ESC W, GS$, GS ( Q, and GS \
• Commands using y: ESC SP, ESC \$, ESC W, ESC \, FS S, GS ( Q, and GS V
• Setting of this command is effective until ESC @ is executed, the printer is reset, or the power is turned off.
• The calculated result from combining this command with others is truncated to the minimum value of the mechanical pitch.
• This command does not affect the current setting values.

# 11 POS examples

The examples will use tree sample tables with a few rows. You should create those tables before running the examples.

## 11.1 Tables

The tables for the example are:

• terminal, a POS terminal information
• ticketl, ticket lines

Copy
<script>

// ======================================================
// TERMINAL TABLE
// ======================================================
Ax.db.execute(DROP TABLE IF EXISTS terminal);

Ax.db.execute(
CREATE TABLE terminal (
term_code char(20) not null,
term_name varchar(20) not null,
country_code char(3) not null,
term_state varchar(20) not null,
term_city char(10) not null,
term_zipcode char(10) not null,
term_direcc varchar(60),
term_telef1 char(20)
)
);
Ax.db.execute(INSERT INTO terminal VALUES('TERM_01','TERMINAL 01','SPAIN','BARCELONA','BARCELONA','08017', 'Vallespir 56','678876523'););

// ======================================================
// ======================================================
Ax.db.execute(DROP TABLE IF EXISTS ticketh);

Ax.db.execute(CREATE TABLE ticketh (
term_code char(10) not null,
ticket_number char(20) not null,
numfac char(20),
nomdoc char(40) not null,
fecini datetime year to second default current year to second not null,
fecfin datetime year to second
));

Ax.db.execute(INSERT INTO ticketh VALUES('TERM_01','Andrew John','T0956665-09','FTERM_0120-35234','DIRECT SALES',CURRENT -5 UNITS MINUTE,CURRENT););

// ======================================================
// TICKET LINES TABLE
// ======================================================
Ax.db.execute(DROP TABLE IF EXISTS ticketl);

Ax.db.execute(CREATE TABLE ticketl (
ticket_number char(20) not null,
seqno smallint not null,
codean char(15) not null,
cantid_1 integer not null,
price decimal(14,2) not null,
discount decimal(14,2) not null,
impnet decimal(14,2) not null,
desvar varchar(255)
));

Ax.db.execute(INSERT INTO ticketl VALUES('T0956665-09',2,'9875435435',1,45.25,0,45.25, 'Green Jacket Snow Patrol'););
Ax.db.execute(INSERT INTO ticketl VALUES('T0956665-09',4,'9875433490',1,12.90,-10,11.61, 'Sunglasses New orizon'););
</script>

## 11.2 POS recepit

The following example shows how to print a receipt ticket using some sample database tables.

Copy
<script>

// ======================================================
// ======================================================
var rs_terminal = Ax.db.executeQuery(
SELECT term_code,  term_name, country_code, term_state, term_city, term_zipcode, term_direcc,term_telef1
FROM terminal WHERE term_code = 'TERM_01'
).toOne();

var rs_ticketh = Ax.db.executeQuery(
SELECT login_name,ticket_number,  numfac, nomdoc, fecini, fecfin
FROM ticketh WHERE term_code = 'TERM_01'
).toOne();

let rs_ticketl = Ax.db.executeQuery(
SELECT seqno,  codean,   cantid_1, price,  discount, impnet,  desvar
FROM  ticketl
WHERE ticketl.ticket_number = ?
ORDER BY 1
, rs_ticketh.ticket_number).toMemory();

let rs_ticketc = Ax.db.executeQuery(
SELECT seqno, pay_type,  pay_amount,  pay_return
FROM ticketc
WHERE ticketc.ticket_number = ?
ORDER BY 1
, rs_ticketh.ticket_number).toMemory();

// ======================================================
// PRINT SECTION
// ======================================================

var m_cut ="-------------------------------------------";
var pos = new Ax.pos.POSPrinter().build();

// ====================================================
// ====================================================

pos
.setCharacterCodeTable(Ax.pos.POSPrinter.CharacterCodeTable.PC437)
.setAlign("center")
.setCharacterSize(Ax.pos.POSPrinter.Width.X3, Ax.pos.POSPrinter.Height.X3)
.setUnderline(Ax.pos.POSPrinter.Underline.TWO_DOT)
.setEmphasize(true)
.text(rs_terminal.term_name)
.printAndFeedLine()
.setEmphasize(false)
.setUnderline(Ax.pos.POSPrinter.Underline.CANCEL)
.text(rs_terminal.term_direcc).printAndFeedLine()
.text(rs_terminal.term_zipcode + '-' + rs_terminal.term_city)
.printAndFeedLine()
.text(rs_terminal.term_telef1 )
.printAndFeedLine()
.text("NIF: A282382832")
.printAndFeedLines(2)
.setUnderline(Ax.pos.POSPrinter.Underline.TWO_DOT)
.setEmphasize(true)
.text(rs_ticketh.nomdoc).printAndFeedLine()
.setEmphasize(false)
.printAndFeedLines(2)
;

// ====================================================
// Reduce character size
// ====================================================

pos
.setCharacterSize(Ax.pos.POSPrinter.Width.X1, Ax.pos.POSPrinter.Height.X1)
.setAlign("left")
.text("Document:" + rs_ticketh.ticket_number).printAndFeedLine()
.text(" Invoice:" + rs_ticketh.numfac).printAndFeedLine()
.text("    Date:" + rs_ticketh.fecfin.toGMTString()).printAndFeedLine()
.printAndFeedLine()
.setAlign("center")
.text("ITEMS")
.printAndFeedLine()
.setAlign("left")
.text(m_cut)
.printAndFeedLine()
.text("Product")
.printAndFeedLine()
.text("Qty. EAN           Price   %dct Net total")
.printAndFeedLine()
.text("---- ------------- ------- ---- ---------")
.printAndFeedLine()
;

// ====================================================
// ROWS
// ====================================================
var country_money= "Eur";

var total= 0;

for (let ticketl of rs_ticketl) {
var the_line1 = ticketl.desvar;
var the_line2 = Ax.lang.String.format("%4d %13s %6.3f %4.0f%% %6.2f %3s",
ticketl.cantid_1,
ticketl.codean,
ticketl.price,
ticketl.discount,
ticketl.impnet,
country_money
);
pos
.text(the_line1)
.printAndFeedLine()
.text(the_line2)
.printAndFeedLine();

total = total + ticketl.impnet
}
var total_print = total + ' ';

pos
.printAndFeedLines(1)
.text(m_cut)
.printAndFeedLine();

pos
.setAlign("right")
.text("TOTAL: " + total_print +  country_money + "     ")
.printAndFeedLine()
.printAndFeedLines(2)
;

pos
.setAlign("left")
.printAndFeedLine()
.printAndFeedLines(2)
.printAndFeedLines(2)
.setAlign("center")
.text("--- Thanks for your vist @ ---")
.printAndFeedLines(5)
.cut(Ax.pos.POSPrinter.CutA.PARTIAL)
;

// ====================================================
// SEND TO LPR
// ====================================================
console.log(pos.getBytes());

var lpr = new Ax.net.LPRClient("192.168.12.125");
lpr.setTimeout(5000);
console.log(lpr.getQueueState());

var job = lpr.print(pos.getBytes());
console.log("PRINT ID:" + job);
console.log(lpr.getQueueState());
</script>

## 11.3 PDF recepit

The following example shows a way to generate a receipt in PDF and use PDF and POS libraries to send it directly to a printer without using any specific driver (no need of CUPS).

Copy
<script>

// ======================================================
// ======================================================
var rs_terminal = Ax.db.executeQuery(
SELECT term_code, term_name, country_code, term_state, term_city, term_zipcode, term_direcc, term_telef1
FROM terminal WHERE term_code = 'TERM_01'
).toOne();

var rs_ticketh = Ax.db.executeQuery(
SELECT login_name,ticket_number,  numfac, nomdoc, fecini, fecfin
FROM ticketh WHERE term_code = 'TERM_01'
).toOne();

let rs_ticketl = Ax.db.executeQuery(
SELECT seqno,  codean,   cantid_1, price,  discount, impnet,  desvar
FROM  ticketl
WHERE ticketl.ticket_number = ?
ORDER BY 1
, rs_ticketh.ticket_number).toMemory();

// ======================================================
// PRINT SECTION
//
// Create a formatter on specific language and set
// numbers to 2 decimals
// ======================================================

var formatter    = new Ax.util.LocaleFormatter("es").setScale(2);
var font_size    = 7;
var paper_width  = 8.0;
var paper_height = 12.0;

// ======================================================
// PRINT DATA
// ======================================================

var company_name = "ACME SPORTS";

var ticket       =  {
total: 53.86,
base: 65.18,
iva: 11.32
}

"ACME SPORTS INC",
"A373473733",
"MENLO PARK",
"38383 SAN FRACISCO (CA)",
"+1 9394394939393",
"service@apple.com",
"ww.apple.com",
];
"Fac. Simplif: 64200/00048/2018/T0046469",
"TICKET: 00048005957",
"FECHA: 27/12/2018 HORA: 10:03",
];

// ====================================================================
// 1. Create document layout with page size and margins
// ====================================================================

var root = new Ax.fop.DocumentBuilder().createDocument(paper_width, paper_height, 0, 0, 0, 0);
root.getSimplePageMaster().setMargins(0.5, 0.5, 0.5, 0.5);
root.setDebug("");

// ====================================================================
// 2. Create a body flow
// ====================================================================

var flow = root.getBodyFlow();

// ====================================================================
// ====================================================================
.setFontSize(font_size)
.setTextAlign("center")
// Add child on this block
.build(c => {
});
.setLineHeight("10pt")
.setRuleThickness("0.5pt")
}
);

// ====================================================================
// 4. Add body block (lines) in a TABLE
// ====================================================================

"Unid.",
"Articulo",
"PVP",
"%Dto",
"Precio",
]).forEach(c => {
c.getCell().setBorderBottomStyle("solid").setBorderBottomWidth(0.5);
c.getCell().setTextAlign("center");
});

for (var row of rs_ticketl) {
table.getBody().addRow([ row.get("cantid_1"), row.get("codean"), formatter.format(row.get("price")), formatter.format(row.get("discount")), formatter.format(row.get("impnet")) ])
.forEach(c => {
if (c.getColumnIndex() > 1)
c.setTextAlign("end");
});
}
table.setSpaceAfter("5pt");
table.pack();

// ====================================================================
// 5. Add footer block (totals)
// ====================================================================
.setProvisionalDistanceBetweenStarts("6cm")
.setProvisionalLabelSeparation("3pt")
})
})
})
;

// ====================================================================
// ====================================================================
.setRuleThickness("0.5pt")
;

// ====================================================================
// GENERATE PDF
// ====================================================================

var receipt_fop = root.toFOP();
let receipt_pdf = new Ax.fop.Processor().transform(receipt_fop);

// ====================================================================
// Convert PDF TO PNG IMAGE
// ====================================================================

// ====================================================================
// Convert PNG image to POS RASTER IMAGE
//
// Epson TM M30 Epson TM-m30, 8 Points / mm (203 dpi)
//
// Paper is 8cm (8 / 2.5) = 3.14 inches
//
// 3.14 * 203 = 637.42 pixels
// ====================================================================

var receipt_bmp = new Ax.pos.POSImage(receipt_png).scaleToFit(600).toRaster();

// ====================================================================
// SAVE FILES FOR DEBUG
// ====================================================================
new Ax.io.File("/tmp/PDFticket.fop").write(receipt_fop);
new Ax.io.File("/tmp/PDFticket.pdf").write(receipt_pdf);
new Ax.io.File("/tmp/PDFticket.png").write(receipt_png);

// ====================================================================
// Crate A POS SEQUENCE (RASTER + CUT PAPER)
// ====================================================================
var pos = new Ax.pos.POSPrinter()
.build()
.write(receipt_bmp)
.printAndFeedLines(1)
.cut(Ax.pos.POSPrinter.CutA.PARTIAL);

// ====================================================================
// SEND POS SEQUENCE TO PRINTER
//
// VOILA! SEND A PDF DIRECTLY TO POS WITHOUT DRIVER!
// ====================================================================
var lpr = new Ax.net.LPRClient("192.168.12.125");
lpr.setTimeout(5000);
var job = lpr.print(pos.getBytes());
console.log(lpr.getQueueState());

</script>