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.
This commit is contained in:
parent
410db93c30
commit
b4cbfa71aa
@ -210,9 +210,14 @@ export function generateContractPdf(contract: ContractForPdf): Promise<Buffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Fußzeile mit Hinweis auf allen Seiten ---
|
// --- 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;
|
const pageCount = doc.bufferedPageRange().count;
|
||||||
for (let i = 0; i < pageCount; i++) {
|
for (let i = 0; i < pageCount; i++) {
|
||||||
doc.switchToPage(i);
|
doc.switchToPage(i);
|
||||||
|
const bottomMargin = doc.page.margins.bottom;
|
||||||
|
doc.page.margins.bottom = 0;
|
||||||
doc.fontSize(7.5).fillColor('#888888').text(
|
doc.fontSize(7.5).fillColor('#888888').text(
|
||||||
'Automatisiert aus den Angaben in der WG-Verwaltungs-App erstellte Vertragsvorlage — keine Rechtsberatung, ' +
|
'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}.`,
|
`keine Gewähr für rechtliche Vollständigkeit. Seite ${i + 1} von ${pageCount}.`,
|
||||||
@ -220,6 +225,7 @@ export function generateContractPdf(contract: ContractForPdf): Promise<Buffer> {
|
|||||||
doc.page.height - 40,
|
doc.page.height - 40,
|
||||||
{ width: doc.page.width - 112, align: 'center' },
|
{ width: doc.page.width - 112, align: 'center' },
|
||||||
);
|
);
|
||||||
|
doc.page.margins.bottom = bottomMargin;
|
||||||
doc.fillColor('#000000');
|
doc.fillColor('#000000');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user