diff --git a/svc/routes/customer_balance_pdf.go b/svc/routes/customer_balance_pdf.go index 6a1e26e..4c065ab 100644 --- a/svc/routes/customer_balance_pdf.go +++ b/svc/routes/customer_balance_pdf.go @@ -289,7 +289,7 @@ func drawCustomerBalancePDF( } wrappedLines := func(text string, w float64) [][]byte { - t := strings.TrimSpace(text) + t := strings.TrimSpace(sanitizePDFText(text)) if t == "" { t = "-" } @@ -321,7 +321,7 @@ func drawCustomerBalancePDF( cy := startY for _, ln := range lines { pdf.SetXY(x+1, cy) - pdf.CellFormat(w-2, lineH, string(ln), "", 0, align, false, 0, "") + pdf.CellFormat(w-2, lineH, sanitizePDFText(string(ln)), "", 0, align, false, 0, "") cy += lineH } } @@ -404,7 +404,7 @@ func drawCustomerBalancePDF( drawWrapped(v, x, y, summaryW[i], rowH, 3.2, "L") } else { pdf.SetXY(x+1, y+(rowH-4.2)/2) - pdf.CellFormat(summaryW[i]-2, 4.2, v, "", 0, align, false, 0, "") + pdf.CellFormat(summaryW[i]-2, 4.2, sanitizePDFText(v), "", 0, align, false, 0, "") } x += summaryW[i] } @@ -491,7 +491,7 @@ func drawCustomerBalancePDF( drawWrapped(v, rowX, rowY, detailW[i], rowH, 3.0, "L") } else { pdf.SetXY(rowX+1, rowY+(rowH-4.0)/2) - pdf.CellFormat(detailW[i]-2, 4.0, v, "", 0, align, false, 0, "") + pdf.CellFormat(detailW[i]-2, 4.0, sanitizePDFText(v), "", 0, align, false, 0, "") } rowX += detailW[i] } @@ -555,3 +555,17 @@ func absFloat(v float64) float64 { } return v } + +func sanitizePDFText(s string) string { + s = strings.ToValidUTF8(s, "?") + s = strings.ReplaceAll(s, "\x00", " ") + return strings.Map(func(r rune) rune { + if r == '\n' || r == '\r' || r == '\t' { + return ' ' + } + if r < 32 { + return -1 + } + return r + }, s) +} diff --git a/svc/routes/statement_aging_pdf.go b/svc/routes/statement_aging_pdf.go index 8ee3eba..e5947bd 100644 --- a/svc/routes/statement_aging_pdf.go +++ b/svc/routes/statement_aging_pdf.go @@ -327,21 +327,21 @@ func drawStatementAgingPDF(pdf *gofpdf.Fpdf, p models.StatementAgingParams, mast pdf.SetFont("dejavu", "B", 15) pdf.SetTextColor(colorPrimary[0], colorPrimary[1], colorPrimary[2]) pdf.SetXY(marginL, marginT) - pdf.CellFormat(150, 7, "Cari Yaşlandırmalı Ekstre", "", 0, "L", false, 0, "") + pdf.CellFormat(150, 7, sanitizePDFText("Cari Yaşlandırmalı Ekstre"), "", 0, "L", false, 0, "") pdf.SetFont("dejavu", "", 9) pdf.SetTextColor(20, 20, 20) pdf.SetXY(pageW-marginR-95, marginT+1) - pdf.CellFormat(95, 5, "Son Tarih: "+p.EndDate, "", 0, "R", false, 0, "") + pdf.CellFormat(95, 5, sanitizePDFText("Son Tarih: "+p.EndDate), "", 0, "R", false, 0, "") pdf.SetXY(pageW-marginR-95, marginT+6) - pdf.CellFormat(95, 5, "Cari: "+p.AccountCode, "", 0, "R", false, 0, "") + pdf.CellFormat(95, 5, sanitizePDFText("Cari: "+p.AccountCode), "", 0, "R", false, 0, "") mode := "1_2" if len(p.Parislemler) > 0 { mode = strings.Join(p.Parislemler, ",") } pdf.SetXY(pageW-marginR-95, marginT+11) - pdf.CellFormat(95, 5, "Parasal İşlem: "+mode, "", 0, "R", false, 0, "") + pdf.CellFormat(95, 5, sanitizePDFText("Parasal İşlem: "+mode), "", 0, "R", false, 0, "") pdf.SetDrawColor(colorPrimary[0], colorPrimary[1], colorPrimary[2]) pdf.Line(marginL, marginT+16, pageW-marginR, marginT+16) @@ -362,7 +362,7 @@ func drawStatementAgingPDF(pdf *gofpdf.Fpdf, p models.StatementAgingParams, mast for i, c := range cols { pdf.Rect(x, y, widths[i], h, "DF") pdf.SetXY(x+0.8, y+1.0) - pdf.CellFormat(widths[i]-1.6, h-2.0, c, "", 0, "C", false, 0, "") + pdf.CellFormat(widths[i]-1.6, h-2.0, sanitizePDFText(c), "", 0, "C", false, 0, "") x += widths[i] } pdf.SetY(y + h) @@ -387,7 +387,7 @@ func drawStatementAgingPDF(pdf *gofpdf.Fpdf, p models.StatementAgingParams, mast align = "C" } pdf.SetXY(x+0.8, y+0.8) - pdf.CellFormat(widths[i]-1.6, h-1.6, v, "", 0, align, false, 0, "") + pdf.CellFormat(widths[i]-1.6, h-1.6, sanitizePDFText(v), "", 0, align, false, 0, "") x += widths[i] } pdf.SetY(y + h)