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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
This commit is contained in:
@@ -98,8 +98,12 @@ function wrapText(text: string, maxWidth: number, font: EmbeddedFont, size: numb
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawSection(state: State, title: string): void {
|
function drawSection(state: State, title: string): void {
|
||||||
|
const yBefore = state.y
|
||||||
ensureSpace(state, SECTION_GAP + LINE_HEIGHT + 6)
|
ensureSpace(state, SECTION_GAP + LINE_HEIGHT + 6)
|
||||||
|
// Only add gap if we didn't just start a new page
|
||||||
|
if (state.y === yBefore) {
|
||||||
state.y -= SECTION_GAP
|
state.y -= SECTION_GAP
|
||||||
|
}
|
||||||
currentPage(state).drawRectangle({
|
currentPage(state).drawRectangle({
|
||||||
x: MARGIN, y: state.y - 4,
|
x: MARGIN, y: state.y - 4,
|
||||||
width: PAGE_WIDTH - MARGIN * 2, height: LINE_HEIGHT + 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})`)
|
drawSection(state, `CAPA Actions (${data.capas.length})`)
|
||||||
for (let i = 0; i < data.capas.length; i++) {
|
for (let i = 0; i < data.capas.length; i++) {
|
||||||
const c = data.capas[i]
|
const c = data.capas[i]
|
||||||
ensureSpace(state, LINE_HEIGHT)
|
ensureSpace(state, LINE_HEIGHT * 4)
|
||||||
currentPage(state).drawText(`#${i + 1}`, {
|
currentPage(state).drawText(`#${i + 1}`, {
|
||||||
x: MARGIN, y: state.y,
|
x: MARGIN, y: state.y,
|
||||||
size: BODY_FONT_SIZE, font: boldFont, color: rgb(0, 0, 0),
|
size: BODY_FONT_SIZE, font: boldFont, color: rgb(0, 0, 0),
|
||||||
|
|||||||
Reference in New Issue
Block a user