package main import ( "github.com/signintech/gopdf" "encoding/csv" "os" "log" "fmt" "math" ) func main() { // Prepare data file, err := os.Open("list.csv") if err != nil { log.Fatalln("Error while reading file: " + err.Error()) } reader := csv.NewReader(file) reader.LazyQuotes = true records, errRecords := reader.ReadAll() if errRecords != nil { log.Fatalln("Error while parsing file: " + errRecords.Error()) } log.Println("hey") defer file.Close() // Prepare document pdf := &gopdf.GoPdf{} pdf.Start(gopdf.Config{ PageSize: *gopdf.PageSizeA4, }) pdf.AddTTFFont("inter", "./inter.ttf") pdf.SetFont("inter", "", 10) var tableEntries [][]string var tablePageIndex = 0 var tablePageLength = 31 // Write data to document for index, record := range records { tableEntries = append(tableEntries, []string{ fmt.Sprintf("%d", index), record[3], record[5], }) if index % 31 == 0 { pdf.AddPage() } } iterations := math.Ceil(float64(len(tableEntries)) / 31.0) fmt.Println(iterations) for i := 0; i < int(iterations); i += 1 { // create each page here table := pdf.NewTableLayout(24, 24, 24, 24) table.AddColumn("#", 20, "left") table.AddColumn("Name", 160, "left") table.AddColumn("Fächer", 360, "left") for i := tablePageIndex; i < tablePageIndex + tablePageLength; i += 1 { table.AddRow() } tablePageIndex += tablePageLength } // table.SetTableStyle(gopdf.CellStyle{ // BorderStyle: gopdf.BorderStyle{ // Top: true, // Left: true, // Bottom: true, // Right: true, // Width: 1.0, // }, // FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255}, // TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0}, // FontSize: 10, // }) // // Set the style for table header // table.SetHeaderStyle(gopdf.CellStyle{ // BorderStyle: gopdf.BorderStyle{ // Top: true, // Left: true, // Bottom: true, // Right: true, // Width: 2.0, // RGBColor: gopdf.RGBColor{R: 100, G: 150, B: 255}, // }, // FillColor: gopdf.RGBColor{R: 255, G: 200, B: 200}, // TextColor: gopdf.RGBColor{R: 255, G: 100, B: 100}, // Font: "font2", // FontSize: 12, // }) // table.SetCellStyle(gopdf.CellStyle{ // BorderStyle: gopdf.BorderStyle{ // Right: true, // Bottom: true, // Width: 0.5, // RGBColor: gopdf.RGBColor{R: 0, G: 0, B: 0}, // }, // FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255}, // TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0}, // Font: "font1", // FontSize: 10, // }) table.DrawTable() // Finish document pdf.WritePdf("vvliste.pdf") }