package utils import ( "github.com/signintech/gopdf" ) const ( ValignTop = 1 ValignMiddle = 2 ValignBottom = 3 ) const ( AlignLeft = 4 AlignCenter = 5 AlignRight = 6 ) func RectFillColor(pdf *gopdf.GoPdf, text string, fontSize int, x, y, w, h float64, r, g, b uint8, align, valign int, ) { pdf.SetLineWidth(0.8) pdf.SetTextColor(r, g, b) pdf.SetX(x) pdf.SetY(y) pdf.CellWithOption(&gopdf.Rect{W: w, H: h}, text, gopdf.CellOption{Align: align | valign, Border: gopdf.Left | gopdf.Right | gopdf.Bottom | gopdf.Top, }) } func RectFillColorMultiCell(pdf *gopdf.GoPdf, text string, fontSize int, x, y, w, h float64, r, g, b uint8, align, valign int, ) { pdf.SetLineWidth(0.8) pdf.SetFillColor(255, 255, 255) //setup fill color pdf.RectFromUpperLeftWithStyle(x, y, w, h, "FD") lineTexts, _ := pdf.SplitText(text, w) if len(lineTexts) == 0 { pdf.SetX(x) pdf.SetY(y) pdf.MultiCell(&gopdf.Rect{W: w, H: h}, "") return } if len(lineTexts) > 1 { w -= 4 lineTexts, _ = pdf.SplitText(text, w) x += 4 } else { if align == gopdf.Center { textw, _ := pdf.MeasureTextWidth(lineTexts[0]) x = x + (w / 2) - (textw / 2) } else if align == gopdf.Right { textw, _ := pdf.MeasureTextWidth(lineTexts[0]) x = x + w - textw } } pdf.SetTextColor(r, g, b) pdf.SetX(x) if valign == gopdf.Middle { y = y + (h-float64(fontSize*len(lineTexts)))/2 } else if valign == gopdf.Bottom { y = y + h - float64(fontSize*len(lineTexts[0])) } pdf.SetY(y) pdf.MultiCell(&gopdf.Rect{W: w, H: h}, text) }