MCPcopy
hub / github.com/signintech/gopdf / TestTableWithStyledRows

Function TestTableWithStyledRows

table_test.go:223–378  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

221}
222
223func TestTableWithStyledRows(t *testing.T) {
224 // Create a new PDF document
225 pdf := &gopdf.GoPdf{}
226 // Start the PDF with a custom page size (we'll adjust it later)
227 pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 430, H: 200}})
228 // Add a new page to the document
229 pdf.AddPage()
230
231 err := pdf.AddTTFFont("LiberationSerif-Regular", "./test/res/LiberationSerif-Regular.ttf")
232 if err != nil {
233 t.Fatalf("Error loading font: %v", err)
234 return
235 }
236
237 err = pdf.SetFont("LiberationSerif-Regular", "", 11)
238 if err != nil {
239 t.Fatalf("Error set font: %v", err)
240 return
241 }
242 err = pdf.AddTTFFont("Ubuntu-L.ttf", "./examples/outline_example/Ubuntu-L.ttf")
243 if err != nil {
244 t.Fatalf("Error loading font: %v", err)
245 return
246 }
247
248 err = pdf.SetFont("Ubuntu-L.ttf", "", 11)
249 if err != nil {
250 t.Fatalf("Error set font: %v", err)
251 return
252 }
253
254 // Set the starting Y position for the table
255 tableStartY := 10.0
256 // Set the left margin for the table
257 marginLeft := 10.0
258
259 // Create a new table layout
260 table := pdf.NewTableLayout(marginLeft, tableStartY, 25, 5)
261
262 // Add columns to the table
263 table.AddColumn("CODE", 50, "left")
264 table.AddColumn("DESCRIPTION", 200, "left")
265 table.AddColumn("QTY.", 40, "right")
266 table.AddColumn("PRICE", 60, "right")
267 table.AddColumn("TOTAL", 60, "right")
268
269 // Add rows to the table
270 table.AddStyledRow([]gopdf.RowCell{
271 gopdf.NewRowCell("001", gopdf.CellStyle{
272 TextColor: gopdf.RGBColor{R: 255, G: 0, B: 0},
273 }),
274 gopdf.NewRowCell("Product A", gopdf.CellStyle{
275 TextColor: gopdf.RGBColor{R: 255, G: 0, B: 0},
276 }),
277 gopdf.NewRowCell("2", gopdf.CellStyle{
278 TextColor: gopdf.RGBColor{R: 255, G: 0, B: 0},
279 }),
280 gopdf.NewRowCell("10.00", gopdf.CellStyle{

Callers

nothing calls this directly

Calls 14

StartMethod · 0.95
AddPageMethod · 0.95
AddTTFFontMethod · 0.95
SetFontMethod · 0.95
NewTableLayoutMethod · 0.95
AddColumnMethod · 0.95
AddStyledRowMethod · 0.95
AddRowMethod · 0.95
SetTableStyleMethod · 0.95
SetHeaderStyleMethod · 0.95
SetCellStyleMethod · 0.95
DrawTableMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…