const PDFDocument = require('pdfkit'); const fs = require('fs'); const { spawn } = require('child_process'); const path = require('path'); const info = { deptName: "IT Support", supportEmail: "ITHelp@MaineCC.edu", supportPhone: "(207) 453-5079" } const receiptFooter = `For other technical assistance, contact ${info.deptName}:\n${info.supportEmail}\nor ${info.supportPhone}.`; const mccContractor = { name: "Contracting Company", email: "helpme@contractor.com", phone: "1 (800) 234-5678", site: "www.google.com" }; module.exports = { generateInfo: { credentials(username, studentId) { // Create the output text const infoArray = [ `Username: ${username}`, '', 'Email:', `${username}@kvcc.me.edu`, '', `Student ID: ${studentId}`, '', 'Note: the MyKV Portal uses your username to sign in, not email.', receiptFooter ]; return infoArray.join('\n'); }, maineCC() { // Create the output text const infoArray = [ 'Kennebec Valley Community College is migrating email domains from @kvcc.me.edu to @mainecc.edu.\n', `For support with this transition, please contact:\n${mccContractor.name}`, `${mccContractor.phone}`, `${mccContractor.email}`, `${mccContractor.site}\n`, receiptFooter ]; return infoArray.join('\n'); }, tempPassword(password) { // Create the output text const infoArray = [ 'We have changed your password to a temporary password, shown below. Next time you log into Microsoft you will be prompted to change your password.\n', 'Temporary Password:', `${password}\n`, 'Password requirements:\n8+ characters\n1+ Uppercase\n1+ Lowercase\n1+ Special (!/_=.,?)\n', receiptFooter ]; return infoArray.join('\n'); } }, generatePdf(infoString) { return new Promise((resolve, reject) => { // Define the path for the PDF file const pdfFilePath = path.join(__dirname, '../public/output.pdf'); // Create a new PDF document const doc = new PDFDocument({ size: [204, 400], margin: 5 }); // Create a writable stream to save the PDF to a file const writeStream = fs.createWriteStream(pdfFilePath); doc.pipe(writeStream); // Add content (image, text) to the PDF doc.image('./public/itslogo.jpg', { fit: [196, 100], align: 'center', valign: 'top', }); // Move down below the Logo/Banner image doc.moveDown(); doc.moveDown(); doc.moveDown(); doc.moveDown(); doc.moveDown(); doc.moveDown(); doc.moveDown(); // Write the text from infoString doc.fontSize(12) doc.font('public/Outfit-Regular.ttf').text(infoString, { align: 'left', }); // Finalize the PDF doc.end(); writeStream.on('finish', () => { resolve(); }); // Handle any errors during file writing writeStream.on('error', (err) => { reject(err); }); }) }, print() { return new Promise((resolve, reject) => { // Define the path for the PDF file const pdfFilePath = path.join(__dirname, '../public/output.pdf'); // Start the print command const printer = spawn('lp', ['-d', 'ITThermal', pdfFilePath]); // Handle error if the printing process fails printer.on('error', (err) => { reject(err); }); // Handle the process exit event printer.on('close', (code) => { if (code === 0) { resolve() } else { reject("lp process exited with non-zero result."); } }); }) } }