Skip to main content

to_text

Function to_text 

Source
pub fn to_text(nodes: &[Node]) -> String
Expand description

Lays out nodes as plain text in fixed columns, as an 80 mm printer with Font A (48 columns) would print them. See to_text_with for other widths.

Each printed line becomes a line of text, aligned with spaces and with trailing spaces removed; wide characters (GS !) count as several columns for alignment but are written once. QR codes, barcodes and images appear as [QR: …], [BARCODE …: …] and [IMAGE WxH]. Cuts, drawer pulses, settings and unknown commands produce no text.

use hardless_escpos::parse;
use hardless_render::to_text;
let text = to_text(&parse(b"\x1ba\x02Total: 1,250\n"));
assert_eq!(text, format!("{}Total: 1,250\n", " ".repeat(48 - 12)));