const PDFDocument = require('pdfkit'); const { spawn } = require('child_process'); module.exports = { generateFile(username, studentId) { // Create the output text const infoArray = [ 'Username:', `${username}`, '', 'Email:', `${username}@kvcc.me.edu`, '', 'Student ID:', `${studentId}`, '', 'Note: When signing into the MyKV Portal, use your Username not your Email.', 'For further assistance contact ithelp@mainecc.edu' ]; const infoString = infoArray.join('\n'); // Create a new PDF document const doc = new PDFDocument(); // Create a print process (e.g., using `lp` to print the PDF directly) const printer = spawn('lp', ['-d', 'ITThermal']); // Replace 'printer_name' with your actual printer // Pipe the PDF document output to the printing process doc.pipe(printer.stdin); // Add image and text to the PDF doc.image('itslogo.jpg', { fit: [576, 261], align: 'center', valign: 'top' }); doc.moveDown(); doc.fontSize(16).text(infoString, { align: 'left' }); // Finalize the PDF and close the stream doc.end(); // Listen for the print process to finish printer.on('close', (code) => { if (code === 0) { console.log('Printed successfully'); } else { console.error('Failed to print'); } }); } }