Принтер-это стандартный тепловой принтер, модель POS80Cut с интерфейсом USB.const { PosPrinter } = require("electron-pos-printer");
ipcMain.on("print-receipt", async (_, order) => {
const options = {
preview: false,
margin: "0 0 0 0",
copies: 1,
printerName: printerName,
timeOutPerLine: 400,
pageSize: "80mm",
silent: true,
};
const now = new Date().toLocaleString();
const divider = "-".repeat(42);
const items = order.items.map((item) => {
const name = item.itemName.length > 25
? item.itemName.slice(0, 25) + "…"
: item.itemName;
const line = `${item.quantity.toString().padEnd(5)} ${name}`;
return {
type: "text",
value: line,
style: {
fontSize: "12px",
fontFamily: "monospace",
lineSpace: "300px"
},
};
});
const data = [
{
type: "text",
value: `ORDER ID: ${order.uuid}`,
style: {
fontSize: "20px",
fontWeight: "bold",
textAlign: "center",
}
},
{
type: "text",
value: `Waiter: ${order.waiter.username}`,
style: {
fontSize: "12px",
fontFamily: "monospace",
fontWeight: "bold"
},
},
{
type: "text",
value: `Date: ${now}`,
style: {
fontSize: "12px",
fontFamily: "monospace",
fontWeight: "bold"
},
},
{
type: "text",
value: `Table: ${order.tableNumber}`,
style: {
fontSize: "12px",
fontFamily: "monospace",
fontWeight: "bold"
},
},
{
type: "text",
value: divider,
style: {
fontSize: "12px",
fontFamily: "monospace",
textAlign: "left"
},
},
{
type: "text",
value: "QTY ITEM",
style: {
fontSize: "12px",
fontFamily: "monospace",
fontWeight: "bold",
textAlign: "left"
},
},
{
type: "text",
value: divider,
style: {
fontSize: "12px",
fontFamily: "monospace",
textAlign: "left"
},
},
...items
];
try {
await PosPrinter.print(data, options);
console.log("
} catch (error) {
console.error("
}
});
< /code>
Я попытался добавить расстояние между линиями, разрывы строк, заполнение. Они не работают. И принтер не печатает для любого другого типа, кроме текста. Таким образом, используя таблицу, HTML и т. Д.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -and-doesn