escpos-ts API - v1.0.0
    Preparing search index...

    Class MagicEncode

    Automatic multi-encoding text encoder.

    Wraps a raw-bytes write function and a PrinterProfile to produce correctly encoded ESC/POS byte streams for arbitrary Unicode text.

    Auto mode (default): Characters are grouped by the first code page in the active printer profile that can represent them. A ESC t n switch command is emitted whenever the required code page changes. ASCII characters (< 128) are always emitted as-is without a code-page switch.

    Forced mode: Call forceEncoding to lock all output to a specific code page. Useful when the printer profile and document encoding are both known in advance.

    // Used internally by Escpos β€” you rarely need to construct this directly.
    const encoder = new MagicEncode(
    (buf) => printer._raw(buf),
    ProfileManager.getProfile('default'),
    );
    encoder.write('Hello, δΈ–η•Œ!'); // auto-selects encodings per character

    1.0.0

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Lock all subsequent output to a specific code page, bypassing auto-detection.

      Pass false to return to auto-detection mode.

      Parameters

      • encoding: string | false

        Canonical encoding name (e.g. "CP437") to force, or false to re-enable automatic encoding selection.

      Returns void

      Error if encoding is a string not found in the capabilities database.

      1.0.0

    • Encode and write a UTF-8 string to the printer.

      In auto mode, the string is scanned character by character. ASCII characters are buffered as-is. For non-ASCII characters, the method searches the profile's available code pages for one that can represent the character, emitting a code-page switch (ESC t n) if needed.

      In forced mode (forceEncoding was called with a string), the entire string is encoded with that encoding.

      Parameters

      • text: string

        UTF-8 string to encode and send.

      Returns void

      1.0.0