From c542cce0404cc4c5e3bc32d741bf498eec4791e4 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 9 Sep 2024 13:21:44 -0400 Subject: [PATCH] ! --- mccs-it/thermal/modules/Thermal.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mccs-it/thermal/modules/Thermal.js b/mccs-it/thermal/modules/Thermal.js index 183b6b6..472357e 100644 --- a/mccs-it/thermal/modules/Thermal.js +++ b/mccs-it/thermal/modules/Thermal.js @@ -42,6 +42,28 @@ module.exports = { // Send the PDF file as the response res.end(pdfData); + + // Print the PDF using lp command + const printer = spawn('lp', ['-d', 'ITThermal']); // Replace 'printer_name' with your actual printer name + + // Handle error if the printing process fails + printer.on('error', (err) => { + console.error('Failed to start printing process:', err); + res.status(500).send('Failed to start printing process'); + }); + + // Pipe the PDF data to the printer + printer.stdin.write(pdfData); + printer.stdin.end(); + + // Handle the process exit event + printer.on('close', (code) => { + if (code === 0) { + res.send('PDF sent to printer successfully.'); + } else { + res.status(500).send('Failed to print PDF'); + } + }); }); // Add content (image, text) to the PDF