diff --git a/svc/routes/customer_balance_pdf.go b/svc/routes/customer_balance_pdf.go index 3d76412..3d973da 100644 --- a/svc/routes/customer_balance_pdf.go +++ b/svc/routes/customer_balance_pdf.go @@ -397,6 +397,9 @@ func drawCustomerBalancePDF( totalY := pdf.GetY() totalX := marginL for i, v := range totalsRow { + if i >= len(summaryW) { + break + } pdf.Rect(totalX, totalY, summaryW[i], totalH, "FD") align := "L" if i >= 7 { @@ -441,6 +444,9 @@ func drawCustomerBalancePDF( y := pdf.GetY() x := marginL for i, v := range row { + if i >= len(summaryW) { + break + } pdf.Rect(x, y, summaryW[i], rowH, "") align := "L" if i >= 7 { @@ -520,6 +526,9 @@ func drawCustomerBalancePDF( rowY := pdf.GetY() rowX := marginL for i, v := range line { + if i >= len(detailW) { + break + } pdf.Rect(rowX, rowY, detailW[i], rowH, "") align := "L" if i >= 5 { @@ -557,6 +566,9 @@ func calcPDFRowHeight(pdf *gofpdf.Fpdf, row []string, widths []float64, wrapIdx if !wrapIdx[i] { continue } + if i >= len(widths) || widths[i] <= 2 { + continue + } lines := pdf.SplitLines([]byte(strings.TrimSpace(v)), widths[i]-2) if len(lines) > maxLines { maxLines = len(lines) @@ -570,6 +582,9 @@ func calcPDFRowHeight(pdf *gofpdf.Fpdf, row []string, widths []float64, wrapIdx } func drawPDFCellWrapped(pdf *gofpdf.Fpdf, value string, x, y, w, h float64, align string, lineH float64) { + if w <= 2 || h <= 0 { + return + } text := strings.TrimSpace(value) lines := pdf.SplitLines([]byte(text), w-2) if len(lines) == 0 { diff --git a/svc/routes/statement_aging_pdf.go b/svc/routes/statement_aging_pdf.go index 0a6cb73..ec957b8 100644 --- a/svc/routes/statement_aging_pdf.go +++ b/svc/routes/statement_aging_pdf.go @@ -16,6 +16,12 @@ import ( func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + defer func() { + if rec := recover(); rec != nil { + http.Error(w, fmt.Sprintf("pdf panic: %v", rec), http.StatusInternalServerError) + } + }() + claims, ok := auth.GetClaimsFromContext(r.Context()) if !ok || claims == nil { http.Error(w, "unauthorized", http.StatusUnauthorized)