fix: widen NOTE column and add pagination to study load PDF

This commit is contained in:
2026-08-18 15:44:12 +08:00
parent cefad72416
commit 0d29f0116a
2 changed files with 42 additions and 14 deletions
+20 -14
View File
@@ -36,7 +36,7 @@
const courses = data.courses || [];
const doc = await PDFDocument.create();
const page = doc.addPage([612, 792]); // Letter
let page = doc.addPage([612, 792]); // Letter
const font = doc.embedStandardFont(StandardFonts.Helvetica);
const bold = doc.embedStandardFont(StandardFonts.HelveticaBold);
const margin = 50;
@@ -70,12 +70,12 @@
// Table columns: NOTE, UNITS, TEACHER, COURSE DESCRIPTION, COURSE, GROUP
const cols = [
{ key: 'status', label: 'NOTE', x: margin, w: 40 },
{ key: 'units', label: 'UNITS', x: margin + 40, w: 45 },
{ key: 'teacher', label: 'TEACHER', x: margin + 85, w: 110 },
{ key: 'description', label: 'COURSE DESCRIPTION', x: margin + 195, w: 150 },
{ key: 'courseCode', label: 'COURSE', x: margin + 345, w: 70 },
{ key: 'groupSchedule', label: 'GROUP', x: margin + 415, w: 97 }
{ key: 'status', label: 'NOTE', x: margin, w: 50 },
{ key: 'units', label: 'UNITS', x: margin + 50, w: 45 },
{ key: 'teacher', label: 'TEACHER', x: margin + 95, w: 110 },
{ key: 'description', label: 'COURSE DESCRIPTION', x: margin + 205, w: 150 },
{ key: 'courseCode', label: 'COURSE', x: margin + 355, w: 70 },
{ key: 'groupSchedule', label: 'GROUP', x: margin + 425, w: 87 }
];
const cellSize = 9;
const headerSize = 9;
@@ -84,10 +84,12 @@
const f = isHeader ? bold : font;
const size = isHeader ? headerSize : cellSize;
const linesPerCol = cols.map((c) => wrapText(cells[c.key] || '', f, size, c.w - 6));
const rowHeight = Math.max.apply(null, linesPerCol.map((l) => l.length)) * 11 + 8;
if (y - rowHeight < 50) {
page.drawText('', { x: margin, y: y, size: 1, font, color: black });
return false;
const rowHeight = Math.max(...linesPerCol.map((l) => l.length)) * 11 + 8;
if (!isHeader && y - rowHeight < 50) {
// Row doesn't fit on the current page: start a new page and re-draw the header.
page = doc.addPage([612, 792]);
y = 792 - 50;
drawHeaderRow();
}
if (isHeader) {
page.drawRectangle({ x: margin, y: y - rowHeight, width: contentWidth, height: rowHeight, color: rgb(0.85, 0.9, 0.95) });
@@ -109,9 +111,13 @@
return true;
}
const headerCells = {};
cols.forEach((c) => { headerCells[c.key] = c.label; });
drawRow(headerCells, true);
function drawHeaderRow() {
const headerCells = {};
cols.forEach((c) => { headerCells[c.key] = c.label; });
drawRow(headerCells, true);
}
drawHeaderRow();
for (const course of courses) {
const cells = {