From e7d82f3a5a156ff7767ebb7709cccaf2fee99236 Mon Sep 17 00:00:00 2001 From: weeihan Date: Tue, 28 Jul 2026 16:56:13 +0800 Subject: [PATCH] fix(pdf): skip section gap on new page, reserve space for CAPA label - Fix 1: drawSection now checks if ensureSpace triggered a page break by comparing state.y before/after. Only subtract SECTION_GAP if we're not at the top of a fresh page, avoiding wasting 20px after page breaks. - Fix 2: CAPA loop now reserves LINE_HEIGHT * 4 instead of just LINE_HEIGHT to keep the label and at least a few fields together on the same page. Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9 --- lib/pdf/incident-report.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pdf/incident-report.ts b/lib/pdf/incident-report.ts index f48ce12..2ba3c31 100644 --- a/lib/pdf/incident-report.ts +++ b/lib/pdf/incident-report.ts @@ -98,8 +98,12 @@ function wrapText(text: string, maxWidth: number, font: EmbeddedFont, size: numb } function drawSection(state: State, title: string): void { + const yBefore = state.y ensureSpace(state, SECTION_GAP + LINE_HEIGHT + 6) - state.y -= SECTION_GAP + // Only add gap if we didn't just start a new page + if (state.y === yBefore) { + state.y -= SECTION_GAP + } currentPage(state).drawRectangle({ x: MARGIN, y: state.y - 4, width: PAGE_WIDTH - MARGIN * 2, height: LINE_HEIGHT + 4, @@ -213,7 +217,7 @@ export async function buildIncidentReportPdf(data: IncidentReportData): Promise< drawSection(state, `CAPA Actions (${data.capas.length})`) for (let i = 0; i < data.capas.length; i++) { const c = data.capas[i] - ensureSpace(state, LINE_HEIGHT) + ensureSpace(state, LINE_HEIGHT * 4) currentPage(state).drawText(`#${i + 1}`, { x: MARGIN, y: state.y, size: BODY_FONT_SIZE, font: boldFont, color: rgb(0, 0, 0),