Try dynamic font

This commit is contained in:
Skylar Grant 2024-09-13 09:09:17 -04:00
parent 9363333b5a
commit a870a7119f
2 changed files with 17 additions and 15 deletions

View File

@ -23,16 +23,15 @@ module.exports = {
credentials(username, studentId) { credentials(username, studentId) {
// Create the output text // Create the output text
const infoArray = [ const infoArray = [
`Username: ${username}`, { font: 'public/RobotoMono-Regular.ttf', text: `Username: ${username}` },
'', { font: 'public/Outfit-Regular.ttf', text: '' },
'Email:', { font: 'public/Outfit-Regular.ttf', text: 'Email:' },
`${username}@kvcc.me.edu`, { font: 'public/RobotoMono-Regular.ttf', text: `${username}@kvcc.me.edu` },
'', { font: 'public/Outfit-Regular.ttf', text: '' },
`Student ID: ${studentId}`, { font: 'public/RobotoMono-Regular.ttf', text: `Student ID: ${studentId}` },
'', { font: 'public/Outfit-Regular.ttf', text: '' },
'Note: the MyKV Portal uses your username to sign in, not email.', { font: 'public/Outfit-Regular.ttf', text: 'Note: the MyKV Portal uses your username to sign in, not email.' },
receiptFooter ]
];
return infoArray.join('\n'); return infoArray.join('\n');
}, },
maineCC() { maineCC() {
@ -59,7 +58,7 @@ module.exports = {
return infoArray.join('\n'); return infoArray.join('\n');
} }
}, },
generatePdf(infoString) { generatePdf(infoArray) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Define the path for the PDF file // Define the path for the PDF file
const pdfFilePath = path.join(__dirname, '../public/output.pdf'); const pdfFilePath = path.join(__dirname, '../public/output.pdf');
@ -92,9 +91,12 @@ module.exports = {
// Write the text from infoString // Write the text from infoString
doc.fontSize(12) doc.fontSize(12)
doc.font('public/Outfit-Regular.ttf').text(infoString, { for (row of infoArray) {
doc.moveDown();
doc.font(row.font).text(row.text, {
align: 'left', align: 'left',
}); });
}
// Finalize the PDF // Finalize the PDF
doc.end(); doc.end();

Binary file not shown.