escpos/protocol

Low-level ESC/POS command encoding.

Each function returns a BitArray containing the raw bytes for a single ESC/POS command. These are used internally by the escpos module to build command buffers.

Types

Paper cut mode.

pub type Cut {
  Partial
  Full
}

Constructors

  • Partial
  • Full

Built-in printer font. Available fonts vary by printer model; FontA and FontB are the most widely supported.

pub type Font {
  FontA
  FontB
  FontC
  FontD
  FontE
  SpecialFontA
  SpecialFontB
}

Constructors

  • FontA
  • FontB
  • FontC
  • FontD
  • FontE
  • SpecialFontA
  • SpecialFontB

Image scaling factor for the graphics buffer.

pub type ImageScale {
  Scale1x
  Scale2x
}

Constructors

  • Scale1x
  • Scale2x

Image tone mode. Most printers only support Monochrome.

pub type ImageTone {
  Monochrome
  MultipleTone
}

Constructors

  • Monochrome
  • MultipleTone

Text justification mode.

pub type Justify {
  Left
  Center
  Right
}

Constructors

  • Left
  • Center
  • Right

Print color selection. Most printers only support Color1 (black).

pub type PrintColor {
  Color1
  Color2
  Color3
  Color4
}

Constructors

  • Color1
  • Color2
  • Color3
  • Color4

Values

pub fn bold(on: Bool) -> BitArray

Enables or disables bold text (ESC E).

pub fn character_size(width: Int, height: Int) -> BitArray

Sets character width and height 1–8 (GS !).

pub fn cut(cut: Cut) -> BitArray

Paper cut command (GS V).

pub fn double_strike(on: Bool) -> BitArray

Enables or disables double-strike text (ESC G).

pub fn flip(on: Bool) -> BitArray

Enables or disables 180-degree rotation (ESC V).

pub fn font(font: Font) -> BitArray

Selects a built-in printer font (ESC M).

pub fn image_to_graphics_buffer(
  data: BitArray,
  width: Int,
  height: Int,
  tone: ImageTone,
  scale_x: ImageScale,
  scale_y: ImageScale,
  color: PrintColor,
) -> BitArray

Stores raster image data into the printer’s graphics buffer (GS ( L, fn=112).

pub const init: BitArray

Initialize printer command (ESC @).

pub fn justify(justify: Justify) -> BitArray

Sets text justification (ESC a). Must be at the start of a line to take effect.

pub const lf: BitArray

Line feed byte (LF).

pub fn line_feed(lines: Int) -> BitArray

Feeds the given number of lines, clamped to 1–255 (ESC d).

pub fn print_graphics_buffer() -> BitArray

Prints the contents of the graphics buffer (GS ( L, fn=50).

pub fn reverse(on: Bool) -> BitArray

Enables or disables reverse (white on black) printing (GS B).

pub fn smooth(on: Bool) -> BitArray

Enables or disables character smoothing (GS b).

pub fn underline(on: Bool) -> BitArray

Enables or disables underlined text (ESC -).

pub fn upside_down(on: Bool) -> BitArray

Enables or disables upside-down printing (ESC {).

Search Document