add pagination support for invoice PDF generation to handle long line items

This commit is contained in:
Alaguraj0361 2026-06-03 16:24:03 +05:30
parent a95cbb82fa
commit a6e413a593

View File

@ -221,6 +221,39 @@ const generateInvoicePDF = async (orderData) => {
if (orderData.line_items && orderData.line_items.length > 0) {
for (let i = 0; i < orderData.line_items.length; i++) {
const item = orderData.line_items[i];
// Check if we need to start a new page before drawing this row (A4 page height is 842)
if (tableY > 710) {
// Draw bottom border line for the current page
doc.moveTo(40, tableY - 6)
.lineTo(555, tableY - 6)
.lineWidth(0.5)
.strokeColor('#f1f5f9')
.stroke();
doc.addPage();
tableY = 50;
// Redraw headers on new page
doc.fontSize(9)
.font('Helvetica-Bold')
.fillColor(primaryColor);
doc.text('S.No', 40, tableY, { width: 35 });
doc.text('Product', 85, tableY, { width: 270 });
doc.text('Quantity', 365, tableY, { width: 50, align: 'right' });
doc.text('Unit price', 425, tableY, { width: 60, align: 'right' });
doc.text('Total price', 495, tableY, { width: 60, align: 'right' });
// Line below headers
doc.moveTo(40, tableY + 12)
.lineTo(555, tableY + 12)
.lineWidth(0.8)
.strokeColor(lightGray)
.stroke();
tableY += 25;
}
// Background color for alternating rows (slightly taller: 46 height)
if (i % 2 === 1) {
@ -287,6 +320,10 @@ const generateInvoicePDF = async (orderData) => {
}
// --- 5. TOTALS SECTION ---
if (tableY > 730) {
doc.addPage();
tableY = 50;
}
tableY += 10;
doc.fontSize(10)