escpos
A low-level imperative API for building ESC/POS printer commands.
This module provides a builder-style interface where each function takes
a CommandBuffer and returns a modified buffer. For a declarative
alternative, see escpos/document.
Example
import escpos.{Center, Left}
import escpos/printer
escpos.new()
|> escpos.reset()
|> escpos.align(Center)
|> escpos.bold(True)
|> escpos.writeln("Receipt")
|> escpos.bold(False)
|> escpos.align(Left)
|> escpos.writeln("Item 1 ... $5.00")
|> escpos.cut()
|> printer.print(my_printer)
Types
Printer font. Re-exported from escpos/protocol.
pub type Font =
protocol.Font
Text justification. Re-exported from escpos/protocol.
pub type Justify =
protocol.Justify
Values
pub fn align(
cb: printer.CommandBuffer,
justify: protocol.Justify,
) -> printer.CommandBuffer
Sets text alignment (Left, Center, or Right).
pub fn bold(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables bold text.
pub fn double_strike(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables double-strike text.
pub fn flip(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables 180-degree rotation.
pub fn font(
cb: printer.CommandBuffer,
font: protocol.Font,
) -> printer.CommandBuffer
Sets the printer font.
pub fn image(
cb: printer.CommandBuffer,
image: image.PrintableImage,
) -> printer.CommandBuffer
Prints a monochrome image prepared by the image module.
Example
let assert Ok(pgm) = simplifile.read_bits(from: "./lucy.pgm")
let assert Ok(img) = image.from_pgm(raw_pgm)
let img = image.dither_bayer4x4(img, 0)
escpos.new()
|> escpos.image(img)
|> printer.print(printer)
pub fn image_raster(
cb: printer.CommandBuffer,
image: image.PrintableImage,
) -> printer.CommandBuffer
Prints a monochrome image prepared by the image module. This is using an older
method to print images, useful for some printers that do not understand graphic buffer
commands.
Example
let assert Ok(pgm) = simplifile.read_bits(from: "./lucy.pgm")
let assert Ok(img) = image.from_pgm(raw_pgm)
let img = image.dither_bayer4x4(img, 0)
escpos.new()
|> escpos.image_raster(img)
|> printer.print(printer)
pub fn line_feed(
cb: printer.CommandBuffer,
lines: Int,
) -> printer.CommandBuffer
Feeds the specified number of lines.
pub fn new_line(
cb: printer.CommandBuffer,
) -> printer.CommandBuffer
Appends a single newline.
pub fn partial_cut(
cb: printer.CommandBuffer,
) -> printer.CommandBuffer
Performs a partial paper cut, leaving a small portion connected.
pub fn raw(
cb: printer.CommandBuffer,
data: BitArray,
) -> printer.CommandBuffer
Appends raw bytes to the buffer.
pub fn reset(cb: printer.CommandBuffer) -> printer.CommandBuffer
Resets the printer to its initial state.
pub fn reset_font(
cb: printer.CommandBuffer,
) -> printer.CommandBuffer
Resets the font to the default (FontA).
pub fn reset_text_size(
cb: printer.CommandBuffer,
) -> printer.CommandBuffer
Resets text size to normal (1x1).
pub fn reverse(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables reverse (white on black) text.
pub fn smooth(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables character smoothing.
pub fn text_size(
cb: printer.CommandBuffer,
width: Int,
height: Int,
) -> printer.CommandBuffer
Sets text size multiplier (1-8 for width and height).
pub fn underline(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables underlined text.
pub fn upside_down(
cb: printer.CommandBuffer,
b: Bool,
) -> printer.CommandBuffer
Enables or disables upside-down text.
pub fn write(
cb: printer.CommandBuffer,
text: String,
) -> printer.CommandBuffer
Writes text to the buffer.
pub fn writeln(
cb: printer.CommandBuffer,
text: String,
) -> printer.CommandBuffer
Writes text to the buffer followed by a newline.