This commit is contained in:
Skylar Grant 2024-09-09 13:21:44 -04:00
parent 75a94efca9
commit c542cce040

View File

@ -42,6 +42,28 @@ module.exports = {
// Send the PDF file as the response // Send the PDF file as the response
res.end(pdfData); 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 // Add content (image, text) to the PDF