From b4cbfa71aa1e7a3692daf1fb2ccb81edf0bb0155 Mon Sep 17 00:00:00 2001 From: bernd Date: Thu, 13 Aug 2026 10:43:40 +0000 Subject: [PATCH] Fix generated contract PDF producing extra blank pages Writing the footer near the bottom margin (page.height - 40, past the 56pt bottom margin) made pdfkit's automatic overflow check think the text didn't fit and insert a new page per footer write, doubling the page count with blank pages. Fix: zero out page.margins.bottom while writing the footer, restore it after. --- backend/src/services/contractDocumentGenerator.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/services/contractDocumentGenerator.ts b/backend/src/services/contractDocumentGenerator.ts index 19608e1..f98a0c5 100644 --- a/backend/src/services/contractDocumentGenerator.ts +++ b/backend/src/services/contractDocumentGenerator.ts @@ -210,9 +210,14 @@ export function generateContractPdf(contract: ContractForPdf): Promise { } // --- Fußzeile mit Hinweis auf allen Seiten --- + // Bottom-Margin während des Schreibens auf 0 setzen, sonst löst pdfkit + // beim Schreiben unterhalb der regulären Marge einen automatischen + // Seitenumbruch aus (leere Zusatzseiten als Folge). const pageCount = doc.bufferedPageRange().count; for (let i = 0; i < pageCount; i++) { doc.switchToPage(i); + const bottomMargin = doc.page.margins.bottom; + doc.page.margins.bottom = 0; doc.fontSize(7.5).fillColor('#888888').text( 'Automatisiert aus den Angaben in der WG-Verwaltungs-App erstellte Vertragsvorlage — keine Rechtsberatung, ' + `keine Gewähr für rechtliche Vollständigkeit. Seite ${i + 1} von ${pageCount}.`, @@ -220,6 +225,7 @@ export function generateContractPdf(contract: ContractForPdf): Promise { doc.page.height - 40, { width: doc.page.width - 112, align: 'center' }, ); + doc.page.margins.bottom = bottomMargin; doc.fillColor('#000000'); }