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

Function TestTable

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

Source from the content-addressed store, hash-verified

7)
8
9func TestTable(t *testing.T) {
10 // Create a new PDF document
11 pdf := &gopdf.GoPdf{}
12 // Start the PDF with a custom page size (we'll adjust it later)
13 pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 430, H: 200}})
14 // Add a new page to the document
15 pdf.AddPage()
16
17 err := pdf.AddTTFFont("LiberationSerif-Regular", "./test/res/LiberationSerif-Regular.ttf")
18 if err != nil {
19 t.Fatalf("Error loading font: %v", err)
20 return
21 }
22
23 err = pdf.SetFont("LiberationSerif-Regular", "", 11)
24 if err != nil {
25 t.Fatalf("Error set font: %v", err)
26 return
27 }
28 err = pdf.AddTTFFont("Ubuntu-L.ttf", "./examples/outline_example/Ubuntu-L.ttf")
29 if err != nil {
30 t.Fatalf("Error loading font: %v", err)
31 return
32 }
33
34 err = pdf.SetFont("Ubuntu-L.ttf", "", 11)
35 if err != nil {
36 t.Fatalf("Error set font: %v", err)
37 return
38 }
39
40 // Set the starting Y position for the table
41 tableStartY := 10.0
42 // Set the left margin for the table
43 marginLeft := 10.0
44
45 // Create a new table layout
46 table := pdf.NewTableLayout(marginLeft, tableStartY, 25, 5)
47
48 // Add columns to the table
49 table.AddColumn("CODE", 50, "left")
50 table.AddColumn("DESCRIPTION", 200, "left")
51 table.AddColumn("QTY.", 40, "right")
52 table.AddColumn("PRICE", 60, "right")
53 table.AddColumn("TOTAL", 60, "right")
54
55 // Add rows to the table
56 table.AddRow([]string{"001", "Product A", "2", "10.00", "20.00"})
57 table.AddRow([]string{"002", "Product B", "1", "15.00", "15.00"})
58 table.AddRow([]string{"003", "Product C", "3", "5.00", "15.00"})
59
60 // Set the style for table cells
61 table.SetTableStyle(gopdf.CellStyle{
62 BorderStyle: gopdf.BorderStyle{
63 Top: true,
64 Left: true,
65 Bottom: true,
66 Right: true,

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…