custom-scripts/mccs-it/thermal/modules/Thermal.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-09-09 15:38:53 +00:00
const PDFDocument = require('pdfkit');
const { spawn } = require('child_process');
module.exports = {
2024-09-09 17:05:03 +00:00
generateFile(username, studentId, req, res) {
2024-09-09 17:03:23 +00:00
// 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.',
2024-09-09 17:14:39 +00:00
'',
2024-09-09 17:03:23 +00:00
'For further assistance contact ithelp@mainecc.edu'
];
const infoString = infoArray.join('\n');
// Create a new PDF document in-memory
const doc = new PDFDocument({
2024-09-09 17:15:30 +00:00
size: [204, 400],
margin: 5
2024-09-09 17:03:23 +00:00
});
// Store the PDF in a buffer
let buffers = [];
doc.on('data', buffers.push.bind(buffers));
doc.on('end', () => {
// Combine all the chunks into a single buffer
const pdfData = Buffer.concat(buffers);
// Set the response headers to serve the PDF file
res.writeHead(200, {
'Content-Type': 'application/pdf',
'Content-Disposition': 'inline; filename="output.pdf"', // Or 'attachment' for download
'Content-Length': pdfData.length,
});
// Send the PDF file as the response
res.end(pdfData);
});
// Add content (image, text) to the PDF
doc.image('./public/itslogo.jpg', {
2024-09-09 17:12:49 +00:00
fit: [200, 100],
2024-09-09 17:03:23 +00:00
align: 'center',
valign: 'top',
});
doc.moveDown();
doc.moveDown();
doc.moveDown();
doc.moveDown();
doc.moveDown();
2024-09-09 17:13:21 +00:00
doc.moveDown();
doc.moveDown();
2024-09-09 17:16:05 +00:00
doc.fontSize(12).text(infoString, {
2024-09-09 17:03:23 +00:00
align: 'left',
});
// Finalize the PDF
doc.end();
},
generatePdf() {
}
2024-09-09 15:38:53 +00:00
}