Documentation ¶
Index ¶
Constants ¶
const ( NUL byte = iota // NUL - Null. SOH // SOH - Start of heading. STX // STX - Start of text. ETX // ETX - End of text. EOT // EOT - End of transmission. ENQ // ENQ - Enquiry. ACK // ACK - Acknowledge. BEL // BEL - Bell (beep). BS // BS - Backspace. HT // HT - Horizontal tabulation. LF // LF - Line feed, new line. VT // VT - Vertical tabulation. FF // FF - Form feed, new page. CR // CR - Carriage return. SO // SO - Shift out. SI // SI - Shift in. DLE // DLE - Data Link Escape. DC1 // DC1 - Device control 1. DC2 // DC2 - Device control 2. DC3 // DC3 - Device control 3. DC4 // DC4 - Device control 4. NAK // NAK - Negative acknowledge. SYN // SYN - Synchronous idle. ETB // ETB - End of transmission block. CAN // CAN - Cancel. EM // EM - End of medium. SUB // SUB - Substitute. ESC // ESC - Escape. FS // FS - File separator. GS // GS - Group separator. RS // RS - Record separator. US // US - Unit separator. SP // SP - Space. )
const ( Left = iota Center Right )
const ( NoUnderling = iota OneDotUnderling TwoDotsUnderling )
const ( HRIFontA = iota // (12 x 24) HRIFontB // (9 x 17) )
const ( HRINotPrinted = iota HRIAbove HRIBelow HRIAboveAndBelow )
const ( UpcA = iota UpcE JanEAN8 JanEAN13 Code39 Code93 Code128 ITF NW7 GS1128 GS1Omnidirectional GS1Truncated GS1Limited GS1Expanded )
const ( L = iota // L recovers 7% of data M // M recovers 15% of data Q // Q recovers 25% of data H // H recovers 30% of data )
const ( DrawerPin2 = iota DrawerPin5 )
Variables ¶
This section is empty.
Functions ¶
func ResetGrayLevel ¶ added in v0.1.5
func ResetGrayLevel()
ResetGrayLevel resets the level of gray that should be visible when printing to default value.
func SetGrayLevel ¶ added in v0.1.5
func SetGrayLevel(l uint8)
SetGrayLevel sets the level of gray that should be visible when printing.
Types ¶
type Cmd ¶
type Cmd interface { // Sizing sets the number of characters per line (CPL) and pixels per line (PPL) after the command set has been initialized. Sizing(cpl, ppl int) // CPL returns the set number of characters per line. CPL() int // PPL returns the set number of pixel per line. PPL() int // Write writes raw bytes. // If a writer is not provided or an error occurs during writing, it will panic. Write(bs ...byte) // Text adds printable string along with encoding, if an encoder is provided. // // Since Golang uses UTF-8 character encoding by default, you must provide an encoder // to convert the string according to the specified code page. // // If the encoder is not provided, the text will be printed using the default UTF-8 encoding, // which may result in incorrect printing. Text(s string, enc func(string) []byte) // Init initializes printer. // Clears the data in the print buffer and resets the printer modes. Init() // LeftMargin sets left margin. LeftMargin(n int) // WidthArea sets print area width. WidthArea(n int) // AbsolutePosition sets absolute print position. AbsolutePosition(n int) // Align specifies position alignment. // // b = 0, left justification enabled; // b = 1, center justification enabled; // b = 2, right justification enabled. Align(b byte) // UpsideDown selects upside-down print mode on/off. UpsideDown(b bool) // TabPositions sets horizontal tab position. // Default 8, 16, 24, 32, 40, ..., 232, 240, 248 TabPositions(bs ...byte) // Tab moves the print position to the next horizontal tab position. // Default 8, 16, 24, 32, 40, ..., 232, 240, 248 Tab() // CodePage selects character code table. CodePage(b byte) // CharSize selects character width and height. CharSize(w byte, h byte) // Bold selects emphasized printing. Bold(b bool) // ClockwiseRotation turns 90' clockwise rotation mode on/off. ClockwiseRotation(b bool) // Underling selects/cancels underling mode. // // b = 0, underline mode disabled; // b = 1, underline mode (1-dot thick) enabled; // b = 2, underline mode (2-dot thick) enabled. Underling(b byte) // BarcodeWidth sets the 1D barcode width multiplier. BarcodeWidth(b byte) // BarcodeHeight sets the 1D barcode height, measured in dots. // // 1 <= b <= 255. BarcodeHeight(b byte) // HRIFont selects HRI character font. // // b = 0, font A (12 x 24); // b = 1, font B (9 x 17). HRIFont(b byte) // HRIPosition selects HRI character print position. // // b = 0, not printed; // b = 1, above the barcode; // b = 2, below the barcode; // b = 3, above and below the barcode. HRIPosition(b byte) // Barcode adds a barcode to print. // // m = 0, UpcA; // m = 1, UpcE; // m = 2, JanEAN8; // m = 3, JanEAN13; // m = 4, Code39; // m = 5, Code93; // m = 6, Code128; // m = 7, ITF; // m = 8, NW7; // m = 9, GS1128; // m = 10, GS1Omnidirectional; // m = 11, GS1Truncated; // m = 12, GS1Limited; // m = 13, GS1Expanded. // If m is out of range, Code39 will be used by default. Barcode(m byte, s string) // QRCodeSize sets the size of module. QRCodeSize(b byte) // QRCodeCorrectionLevel sets the correction level. // // b = 0, correction level 7 %; // b = 1, correction level 15 %; // b = 2, correction level 25 %; // b = 3, correction level 30 %. QRCodeCorrectionLevel(b byte) // QRCode adds a QR code to print. QRCode(s string) // Image adds an image to print. Image(img image.Image, invert bool) // Feed prints current buffer and executes n/4mm paper feed. // // 0 <= b <= 255. Feed(b byte) // LineFeed prints the data in the print buffer and feeds one line, based on the current line spacing. LineFeed() // Cut executes the auto-cutter. Cut(m byte, p byte) // FullCut executes the auto-cutter across the full width of the paper. FullCut() // OpenCashDrawer generates pulse to open a cache drawer. OpenCashDrawer(m byte, t1 byte, t2 byte) // Print performs final preparation of the document before printing. Print() }
func NewEscape ¶
NewEscape returns the most popular set of printer commands for the given configuration.
This function creates a new escape sequence command set for printing images and text.
Parameters:
- cpl: characters per line.
- ppl: pixels per line.
- w: the writer to which the commands will be sent.
- opts: a variadic list of options to customize the behavior of the command set.
Options: You can customize various aspects of the postscript command set using the following options:
- WithBarCodeFunc(barCodeFunc): sets a custom function for generating barcodes.
- WithQRCodeFunc(qrCodeFunc): sets a custom function for generating QR codes.
- WithImageFuncVersion(n): switches the image printing function, where:
- n = 1: uses the [GS 8 L ... GS ( L] print image command.
- n = 2: uses the [ESC * ! ... ESC J] print image command.
Note: By default, the obsolete [GS v ...] print image command is used.
Example Usage:
cmd := NewEscape(48, 576, writer, WithImageFuncVersion(2))
In this example, a new escape sequence command set is created with 48 characters per line, 576 pixels per line. The image printing function is set to use the [ESC * ! ... ESC J] command sequence (version 2).
func NewPostscript ¶ added in v0.1.0
NewPostscript returns the postscript set of printer commands configured with the specified parameters.
This function creates a new postscript command set for printing with customizable options.
Parameters:
- cpl: characters per line.
- ppl: pixels per line.
- w: the writer to which the commands will be sent.
- opts: a variadic list of options to customize the behavior of the command set.
Options: You can customize various aspects of the postscript command set using the following options:
- WithBarCodeFunc(barCodeFunc): sets a function for generating barcodes.
- WithQRCodeFunc(qrCodeFunc): sets a function for generating QR codes.
- WithPageHeight(height): sets the page height to the specified value.
Example Usage:
cmd := NewPostscript(48, 576, writer, WithPageHeight(5670), WithBarCodeFunc(barCodeFunc), WithQRCodeFunc(qrCodeFunc))
In this example, a new postscript command set is created with 48 characters per line, 576 pixels per line. The page height is set to 5670 units, and functions for generating barcodes and QR codes are provided.
Default Initialization: If no options are specified, the postscript command set initializes with height: 400 units.
Note: If functions for generating barcodes and QR codes not provided, the call to print them will be skipped.
func NewSkipper ¶
NewSkipper returns a set of methods that skip the execution of unimplemented commands. This writes raw bytes and text to a writer.
func NewStar ¶
NewStar returns the star set of printer commands for the given configuration.
This function creates a new star sequence command set for printing images and text.
Parameters:
- cpl: characters per line.
- ppl: pixels per line.
- w: the writer to which the commands will be sent.
- opts: a variadic list of options to customize the behavior of the command set.
Options: You can customize various aspects of the postscript command set using the following options:
- WithBarCodeFunc(barCodeFunc): sets a custom function for generating barcodes.
- WithQRCodeFunc(qrCodeFunc): sets a custom function for generating QR codes.
Example Usage:
cmd := NewStar(48, 576, writer)
In this example, a new star sequence command set is created with 48 characters per line, 576 pixels per line.
type Options ¶ added in v0.1.1
type Options interface {
// contains filtered or unexported methods
}