From 4b0bc8215727d3a619a8ce687387b56b71846117 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 01:56:33 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/forms/custom-form-builder.tsx | 54 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/components/forms/custom-form-builder.tsx b/src/components/forms/custom-form-builder.tsx index 1668927..bdf1714 100644 --- a/src/components/forms/custom-form-builder.tsx +++ b/src/components/forms/custom-form-builder.tsx @@ -349,24 +349,68 @@ export function CustomFormBuilder() { } doc.setFontSize(fontSize); + const lineH = fontSize * 1.4; + + const drawTablePdf = (rows: string[][], hasHeader: boolean) => { + if (!rows.length) return; + const cols = Math.max(...rows.map((r) => r.length)); + const colW = maxW / cols; + const cellPad = 4; + for (let ri = 0; ri < rows.length; ri++) { + const row = rows[ri]; + // Compute row height based on tallest cell + const cellLines = row.map((c) => + doc.splitTextToSize(applyVariables(c, ctx) || " ", colW - cellPad * 2), + ); + const rowH = Math.max(...cellLines.map((l) => l.length)) * lineH + cellPad * 2; + if (y + rowH > pageH - margin) { + doc.addPage(); + y = margin; + } + // Draw cells + for (let ci = 0; ci < cols; ci++) { + const x = margin + ci * colW; + doc.setDrawColor(180); + doc.rect(x, y, colW, rowH); + const isHeader = hasHeader && ri === 0; + doc.setFont(pdfFont, isHeader ? "bold" : "normal"); + const lines = cellLines[ci] ?? [""]; + let ty = y + cellPad + lineH * 0.8; + for (const ln of lines) { + doc.text(ln, x + cellPad, ty); + ty += lineH; + } + } + y += rowH; + } + y += 6; + }; + for (const seg of segments) { + if (seg.kind === "table") { + drawTablePdf(seg.rows, seg.hasHeader); + continue; + } const text = applyVariables(seg.text, ctx) || " "; - doc.setFont(pdfFont, "normal"); - const lines = doc.splitTextToSize(text, maxW); + doc.setFont(pdfFont, seg.heading && seg.heading > 0 ? "bold" : "normal"); + const indentPx = seg.indent || 0; + const indentPt = indentPx * 0.75; // px → pt + const segMaxW = maxW - indentPt; + const lines = doc.splitTextToSize(text, segMaxW); for (const line of lines) { if (y > pageH - margin) { doc.addPage(); y = margin; } - let x = margin; + let x = margin + indentPt; if (seg.align === "center") x = pageW / 2; else if (seg.align === "right") x = pageW - margin; doc.text(line, x, y, { align: seg.align === "center" ? "center" : seg.align === "right" ? "right" : "left", }); - y += fontSize * 1.4; + y += lineH; } - y += 4; + y += seg.caption ? 2 : 4; } const filenameBase = (renderTitle(ctx) || "Custom_Form").replace(/\s+/g, "_");