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),