Electron JS Print Receipt with electron-pos-printer cuts page too soon and doesn't print...

Discussão em 'Angular' iniciado por Mohid, Maio 6, 2025.

  1. Mohid

    Mohid Guest

    I am building a POS system in Electron JS 35.0.1 and Angular 19. I have installed electron-pos-printer 1.3.6. The printer is triggered by a websocket notification from my backend. Currently the printer does not print the entire receipt. Rather it starts printing and then immediately stops with more than half the receipt stuck in the printer. The printer is a standard thermal printer, POS80CUT model with USB interface.

    Here is my print-receipt handler in my main.js

    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("✅ Receipt printed successfully");
    } catch (error) {
    console.error("❌ Print failed:", error);
    }
    });


    I have tried adding line spacing, line breaks, padding. They don't work. And the printer doesn't print for any other type other than text. So using table, html etc. is out of the question.

    Continue reading...

Compartilhe esta Página