public class EscPosPrintStream
extends java.io.FilterOutputStream
All characters printed by a EscPosPrintStream
are converted into bytes using the
platform's default character encoding.
Constructor and Description |
---|
EscPosPrintStream(java.io.OutputStream out)
Creates an output stream filter for ESC/POS commands built on top of the specified underlying
output stream.
|
Modifier and Type | Method and Description |
---|---|
EscPosPrintStream |
absolutePrintPosition(int n)
Set absolute print position.
|
EscPosPrintStream |
align(byte alignment)
Select alignment.
|
EscPosPrintStream |
bel()
Sounds the buzzer.
|
EscPosPrintStream |
buzzer()
Sounds the buzzer.
|
EscPosPrintStream |
carriageReturn()
Print and carriage return.
|
EscPosPrintStream |
characterSpacing(int n)
Set right-side character spacing.
|
EscPosPrintStream |
charset(java.nio.charset.Charset charset)
Sets the default charset to be used when printing CharSequence to the underlying stream.
|
EscPosPrintStream |
charset(java.lang.String charsetName)
Sets the default charset to be used when printing CharSequence to the underlying stream.
|
EscPosPrintStream |
cr()
Print and carriage return.
|
EscPosPrintStream |
cut(byte cut)
Select cut mode and cut paper.
|
EscPosPrintStream |
doubleStrike(boolean enable)
Turn double-strike mode on/off.
|
EscPosPrintStream |
emphasize(boolean enable)
Turn emphasized mode on/off.
|
EscPosPrintStream |
feed()
Print and return to standard mode (in page mode).
|
EscPosPrintStream |
feedLines(int n)
Prints the data in the print buffer and feeds n lines.
|
EscPosPrintStream |
feedPaper(int n)
Print and feed paper.
|
EscPosPrintStream |
ff()
Print and return to standard mode (in page mode).
|
EscPosPrintStream |
horizontalTab()
Horizontal tab.
|
EscPosPrintStream |
horizontalTabPosition(int... tabPositions)
Set horizontal tab positions.
|
EscPosPrintStream |
ht()
Horizontal tab.
|
EscPosPrintStream |
initialize()
Initialize printer.
|
EscPosPrintStream |
leftMargin(int n)
Set left margin.
|
EscPosPrintStream |
lf()
Print and line feed.
|
EscPosPrintStream |
lineFeed()
Print and line feed.
|
EscPosPrintStream |
lineSpacing(int n)
Set line spacing.
|
EscPosPrintStream |
print(byte... b)
Writes the given bytes to the underlying output stream.
|
EscPosPrintStream |
print(byte b)
Writes the specified byte to the underlying stream.
|
EscPosPrintStream |
print(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array starting at offset off
to the underlying output stream. |
EscPosPrintStream |
print(java.lang.CharSequence text)
Writes the given text to the underlying stream.
|
EscPosPrintStream |
print(EscPosPrintObject... commands)
Writes a set of EscPosPrintObject to the underlying stream.
|
EscPosPrintStream |
print(EscPosPrintObject printStruct)
Writes an EscPosPrintObject to the underlying stream.
|
EscPosPrintStream |
print(int b)
Writes the specified byte to the underlying stream.
|
EscPosPrintStream |
println()
Print and line feed.
|
EscPosPrintStream |
printLogo(byte mode)
Print downloaded bit image using the specified mode (size).
|
EscPosPrintStream |
resetLineSpacing()
Select default line spacing.
|
EscPosPrintStream |
reverseWhiteBlack(boolean enable)
Turn white/black reverse print mode on/off.
|
EscPosPrintStream |
rotate(boolean enable)
Turn 90° clockwise rotation mode on/off.
|
EscPosPrintStream |
rotate(byte value)
Sets 90° clockwise rotation with given value.
|
EscPosPrintStream |
selfTest()
Prints test page and self-diagnostic information.
|
EscPosPrintStream |
shortSelfTest()
Prints current printer parameters, including intensity, temperature of the print head, battery
voltage, speed in case of serial connection, etc.
|
EscPosPrintStream |
textPrintMode(int textPrintMode)
Select print mode(s).
|
EscPosPrintStream |
textSize(byte characterSize)
Select character size
|
EscPosPrintStream |
turnOff()
Switch OFF the printer.
|
EscPosPrintStream |
underline(boolean enable)
Turn underline mode on/off.
|
public EscPosPrintStream(java.io.OutputStream out)
out
- the underlying output stream to be assigned to the field this.out for later
use, or null
if this instance is to be created without an underlying stream.public EscPosPrintStream initialize() throws java.io.IOException
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.
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream feed() throws java.io.IOException
In page mode, prints all the data in the print buffer collectively and switches from page mode to standard mode.
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream ff() throws java.io.IOException
In page mode, prints all the data in the print buffer collectively and switches from page mode to standard mode.
java.io.IOException
- if an I/O error occurs.feed()
public EscPosPrintStream lineFeed() throws java.io.IOException
Prints the data in the print buffer and feeds one line, based on the current line spacing.
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream println() throws java.io.IOException
Prints the data in the print buffer and feeds one line, based on the current line spacing.
java.io.IOException
- if an I/O error occurs.lineFeed()
public EscPosPrintStream lf() throws java.io.IOException
Prints the data in the print buffer and feeds one line, based on the current line spacing.
java.io.IOException
- if an I/O error occurs.lineFeed()
public EscPosPrintStream carriageReturn() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream cr() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.carriageReturn()
public EscPosPrintStream horizontalTab() throws java.io.IOException
Moves the print position to the next horizontal tab position.
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream ht() throws java.io.IOException
Moves the print position to the next horizontal tab position.
java.io.IOException
- if an I/O error occurs.horizontalTab()
public EscPosPrintStream buzzer() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream bel() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.buzzer()
public EscPosPrintStream feedPaper(int n) throws java.io.IOException
Prints the data in the print buffer and feeds the paper n × (vertical or horizontal motion unit).
A motion unit usually measures 1/203 inches or 0.125 mm.
n
- the motion units value to feed, must be inside the range [0,255]java.lang.IllegalArgumentException
- if the value of argument n is outside the range [0,255]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream feedLines(int n) throws java.io.IOException
n
- the number of lines to feed, must be inside the range [0,255]java.lang.IllegalArgumentException
- if the value of argument n is outside the range [0,255]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream textPrintMode(int textPrintMode) throws java.io.IOException
The argument textPrintMode must be one of the EscPosConstants.TEXTPRINTMODE constants defined, or any valid combination of them ored together.
Other values in the range [0,255] may be supported by selected printers, refer to your printer documentation for more details.
textPrintMode
- one of the EscPosConstants.TEXTPRINTMODE constants, or any valid
combination of them ored together.java.lang.IllegalArgumentException
- if the value of argument textPrintMode is outside the range
[0,255]java.io.IOException
- if an I/O error occurs.EscPosConstants.TEXTPRINTMODE_FONT_1
,
EscPosConstants.TEXTPRINTMODE_FONT_2
,
EscPosConstants.TEXTPRINTMODE_EMPHASIZED
,
EscPosConstants.TEXTPRINTMODE_DOUBLE_HEIGHT
,
EscPosConstants.TEXTPRINTMODE_DOUBLE_WIDTH
,
EscPosConstants.TEXTPRINTMODE_UNDERLINE
public EscPosPrintStream textSize(byte characterSize) throws java.io.IOException
The argument characterSize must be one of the EscPosConstants.CHARACTERSIZE constants, or a combination of a width constant with a height constant ored together.
Most printers support only single or double width/height (constants 1 or 2), but other values in the range [0,255] may be supported by selected printers, refer to your printer documentation for more details.
characterSize
- one of the EscPosConstants.CHARACTERSIZE constants, or a combination of a
width constant with a height constant ored together.java.io.IOException
- if an I/O error occurs.CharacterSize
,
EscPosConstants.CHARACTERSIZE_WIDTH_1
,
EscPosConstants.CHARACTERSIZE_WIDTH_2
,
EscPosConstants.CHARACTERSIZE_HEIGHT_1
,
EscPosConstants.CHARACTERSIZE_HEIGHT_2
public EscPosPrintStream underline(boolean enable) throws java.io.IOException
enable
- sets the command to enable or disable underline modejava.io.IOException
- if an I/O error occurs.public EscPosPrintStream emphasize(boolean enable) throws java.io.IOException
enable
- sets the command to enable or disable emphasize modejava.io.IOException
- if an I/O error occurs.public EscPosPrintStream doubleStrike(boolean enable) throws java.io.IOException
enable
- sets the command to enable or disable double-strike modejava.io.IOException
- if an I/O error occurs.public EscPosPrintStream reverseWhiteBlack(boolean enable) throws java.io.IOException
enable
- sets the command to enable or disable white/black reverse print modejava.io.IOException
- if an I/O error occurs.public EscPosPrintStream rotate(boolean enable) throws java.io.IOException
enable
- sets the command to enable or disable 90° clockwise rotation modejava.io.IOException
- if an I/O error occurs.public EscPosPrintStream rotate(byte value) throws java.io.IOException
Provided for printers that define other values for rotation mode besides on/off, refer to your printer documentation for more information.
value
- a valid value for the 'ESC V' command as defined by your printer documentationjava.io.IOException
- if an I/O error occurs.public EscPosPrintStream absolutePrintPosition(int n) throws java.io.IOException
Moves the print position to n × (horizontal or vertical motion unit) from the left edge of the print area.
A motion unit usually measures 1/203 inches or 0.125 mm.
n
- the motion units value to set for the absolute print position from the left edge of
the print area, which mus be in the range [0,65535]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream horizontalTabPosition(int... tabPositions) throws java.io.IOException
A maximum of 32 horizontal tab positions in ascending order can be set, with each value in the range [0,255].
Executing this method with no arguments clears all the set tab positions.
ATTENTION: The maximum amount of tab positions may be lower for some printers - usually any data past the accepted maximum of tab positions will be processed as general data. Refer to your printer documentation before using this command with more than 8 tab positions.
Devices with known maximum number of tab positions:
tabPositions
- A maximum of 32 tab positions in ascending orders, with each value in the
range [0,255], or empty to clear all the set tab positions.java.lang.IllegalArgumentException
- if the maximum number of tab positions is greater than 32, OR
if any given tab position is outside the range [0,255], OR if any given tab position is
less than or equal the preceding value.java.io.IOException
- if an I/O error occurs.public EscPosPrintStream resetLineSpacing() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream lineSpacing(int n) throws java.io.IOException
Sets the line spacing to n × (vertical or horizontal motion unit).
A motion unit usually measures 1/203 inches or 0.125 mm.
n
- the size of the line spacing in motion units, which must be inside the range [0,255]java.lang.IllegalArgumentException
- if the value of argument n is outside the range [0,255]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream characterSpacing(int n) throws java.io.IOException
Sets the right-side character spacing to n × (horizontal or vertical motion unit).
A motion unit usually measures 1/203 inches or 0.125 mm.
n
- the size of the line spacing in motion units, which must be inside the range [0,255]java.lang.IllegalArgumentException
- if the value of argument n is outside the range [0,255]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream align(byte alignment) throws java.io.IOException
Sets the printing alignment to either ALIGN_LEFT, ALIGN_CENTER or ALIGN_RIGHT.
alignment
- the printing alignment, which must be either ALIGN_LEFT, ALIGN_CENTER or
ALIGN_RIGHT.java.lang.IllegalArgumentException
- if the value of argument alignment is not ALIGN_LEFT,
ALIGN_CENTER or ALIGN_RIGHT.java.io.IOException
- if an I/O error occurs.EscPosConstants.ALIGN_LEFT
,
EscPosConstants.ALIGN_CENTER
,
EscPosConstants.ALIGN_RIGHT
public EscPosPrintStream leftMargin(int n) throws java.io.IOException
In standard mode, sets the left margin to n × (horizontal motion unit) from the left edge of the printable area.
A motion unit usually measures 1/203 inches or 0.125 mm.
n
- the motion units value to set the left margin, must be inside the range [0,65535]java.lang.IllegalArgumentException
- if the value of argument n is outside the range [0,65535]java.io.IOException
- if an I/O error occurs.public EscPosPrintStream cut(byte cut) throws java.io.IOException
cut
- the cut mode, which must be either CUT_FULL or CUT_PART.java.lang.IllegalArgumentException
- if the value of argument cut is not either CUT_FULL or
CUT_PARTjava.io.IOException
- if an I/O error occurs.public EscPosPrintStream turnOff() throws java.io.IOException
This command is not listed in the original ESC/POS Manual, refer to the printer's manual to verify support for this command.
Known supported devices:
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream selfTest() throws java.io.IOException
This command is not listed in the original ESC/POS Manual, refer to the printer's manual to verify support for this command.
Known supported devices:
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream shortSelfTest() throws java.io.IOException
This command is not listed in the original ESC/POS Manual, refer to the printer's manual to verify support for this command.
Known supported devices:
java.io.IOException
- if an I/O error occurs.public EscPosPrintStream charset(java.nio.charset.Charset charset) throws java.lang.IllegalArgumentException
charset
- The Charset
to be used to encode the datajava.lang.IllegalArgumentException
- If the given charset is nullpublic EscPosPrintStream charset(java.lang.String charsetName) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
charsetName
- The name of a supported charset
java.lang.IllegalArgumentException
- If the given charsetName is nulljava.io.UnsupportedEncodingException
- If no support for the named charset is availablepublic EscPosPrintStream printLogo(byte mode) throws java.io.IOException
The value of argument mode must be either LOGO_NORMAL, LOGO_DOUBLE_WIDTH, LOGO_DOUBLE_HEIGHT or LOGO_QUADRUPLE.
mode
- the printing mode, which must be either LOGO_NORMAL, LOGO_DOUBLE_WIDTH,
LOGO_DOUBLE_HEIGHT or LOGO_QUADRUPLE.java.lang.IllegalArgumentException
- if the value of argument mode is not LOGO_NORMAL,
LOGO_DOUBLE_WIDTH, LOGO_DOUBLE_HEIGHT or LOGO_QUADRUPLE.java.io.IOException
- if an I/O error occurs.EscPosConstants.LOGO_NORMAL
,
EscPosConstants.LOGO_DOUBLE_WIDTH
,
EscPosConstants.LOGO_DOUBLE_HEIGHT
,
EscPosConstants.LOGO_QUADRUPLE
public EscPosPrintStream print(byte b) throws java.io.IOException
b
- the byte
.java.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(int b) throws java.io.IOException
write
is that one byte is written to the output stream. The byte to be written is the eight low-order
bits of the argument b
. The 24 high-order bits of b
are ignored.b
- the byte
.java.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(byte[] b, int off, int len) throws java.io.IOException
len
bytes from the specified byte array starting at offset off
to the underlying output stream.
If b
is null
, a NullPointerException
is thrown.
If off
is negative, or len
is negative, or off+len
is
greater than the length of the array b
, then an IndexOutOfBoundsException
is thrown.
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.java.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(byte... b) throws java.io.IOException
b
- the data.java.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(java.lang.CharSequence text) throws java.io.IOException
All characters are converted into bytes using the platform's default character encoding.
text
- the datajava.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(EscPosPrintObject printStruct) throws java.io.IOException
printStruct
- an object that writes its own set of ESC/POS commandsjava.io.IOException
- if an I/O error occurs.public EscPosPrintStream print(EscPosPrintObject... commands) throws java.io.IOException
commands
- a set of EscPosPrintStructjava.io.IOException
- if an I/O error occurs.