From 06af84204a8c539c4f6ae9236f88384e1b66d0c4 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Tue, 17 Mar 2026 11:23:20 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/customer_balance_pdf.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/svc/routes/customer_balance_pdf.go b/svc/routes/customer_balance_pdf.go index 3d973da..721317d 100644 --- a/svc/routes/customer_balance_pdf.go +++ b/svc/routes/customer_balance_pdf.go @@ -311,6 +311,9 @@ func drawCustomerBalancePDF( y := pdf.GetY() x := marginL for i, c := range summaryCols { + if i >= len(summaryW) { + break + } pdf.Rect(x, y, summaryW[i], 7, "DF") pdf.SetXY(x+1, y+1.2) pdf.CellFormat(summaryW[i]-2, 4.6, c, "", 0, "C", false, 0, "") @@ -326,6 +329,9 @@ func drawCustomerBalancePDF( y := pdf.GetY() x := marginL for i, c := range detailCols { + if i >= len(detailW) { + break + } pdf.Rect(x, y, detailW[i], 6, "DF") pdf.SetXY(x+1, y+1) pdf.CellFormat(detailW[i]-2, 4, c, "", 0, "C", false, 0, "") @@ -569,7 +575,7 @@ func calcPDFRowHeight(pdf *gofpdf.Fpdf, row []string, widths []float64, wrapIdx if i >= len(widths) || widths[i] <= 2 { continue } - lines := pdf.SplitLines([]byte(strings.TrimSpace(v)), widths[i]-2) + lines := safeSplitLinesPDF(pdf, strings.TrimSpace(v), widths[i]-2) if len(lines) > maxLines { maxLines = len(lines) } @@ -586,7 +592,7 @@ func drawPDFCellWrapped(pdf *gofpdf.Fpdf, value string, x, y, w, h float64, alig return } text := strings.TrimSpace(value) - lines := pdf.SplitLines([]byte(text), w-2) + lines := safeSplitLinesPDF(pdf, text, w-2) if len(lines) == 0 { lines = [][]byte{[]byte("")} } @@ -603,6 +609,19 @@ func drawPDFCellWrapped(pdf *gofpdf.Fpdf, value string, x, y, w, h float64, alig } } +func safeSplitLinesPDF(pdf *gofpdf.Fpdf, text string, width float64) (lines [][]byte) { + if width <= 0 { + width = 1 + } + defer func() { + if recover() != nil { + lines = [][]byte{[]byte(text)} + } + }() + lines = pdf.SplitLines([]byte(text), width) + return lines +} + func formatCurrencyMapPDF(m map[string]float64) string { if len(m) == 0 { return "-"