Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 02:10:15 +00:00
co-authored by renee-png
parent 56f67b55f3
commit 581e4ab6cf
+12 -7
View File
@@ -456,7 +456,7 @@ export function CustomFormBuilder() {
doc.setFontSize(fontSize);
const lineH = fontSize * 1.4;
const drawTablePdf = (rows: string[][], hasHeader: boolean) => {
const drawTablePdf = (rows: TableCellSeg[][]) => {
if (!rows.length) return;
const cols = Math.max(...rows.map((r) => r.length));
const colW = maxW / cols;
@@ -465,19 +465,24 @@ export function CustomFormBuilder() {
const row = rows[ri];
// Compute row height based on tallest cell
const cellLines = row.map((c) =>
doc.splitTextToSize(applyVariables(c, ctx) || " ", colW - cellPad * 2),
doc.splitTextToSize(applyVariables(c.text, 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;
const cell = row[ci];
const borders = cell?.borders ?? DEFAULT_BORDERS;
doc.setDrawColor(120);
doc.setLineWidth(0.5);
if (borders.t) doc.line(x, y, x + colW, y);
if (borders.b) doc.line(x, y + rowH, x + colW, y + rowH);
if (borders.l) doc.line(x, y, x, y + rowH);
if (borders.r) doc.line(x + colW, y, x + colW, y + rowH);
const isHeader = cell?.isHeader ?? false;
doc.setFont(pdfFont, isHeader ? "bold" : "normal");
const lines = cellLines[ci] ?? [""];
let ty = y + cellPad + lineH * 0.8;
@@ -493,7 +498,7 @@ export function CustomFormBuilder() {
for (const seg of segments) {
if (seg.kind === "table") {
drawTablePdf(seg.rows, seg.hasHeader);
drawTablePdf(seg.rows);
continue;
}
const text = applyVariables(seg.text, ctx) || " ";