143 lines
3.0 KiB
Go
143 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"fmt"
|
|
"log"
|
|
"math"
|
|
"os"
|
|
|
|
"github.com/signintech/gopdf"
|
|
)
|
|
|
|
const title string = "Teilnahmeliste der StugA Lehramt GO-Vollversammlung 07.04.2026"
|
|
|
|
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.SetMargins(20, 20, 20, 20)
|
|
|
|
var tableEntries [][]string
|
|
var tablePageIndex = 0
|
|
var tablePageLength = 36
|
|
var isFirst bool = true
|
|
|
|
// Write data to document
|
|
for index, record := range records[1:] {
|
|
tableEntries = append(tableEntries, []string{
|
|
fmt.Sprintf("%d", index+1),
|
|
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
|
|
pdf.AddPage()
|
|
var table gopdf.TableLayout
|
|
|
|
if isFirst {
|
|
pdf.SetFont("inter", "", 12)
|
|
pdf.Cell(nil, title)
|
|
|
|
pdf.SetFont("inter", "", 10)
|
|
isFirst = false
|
|
|
|
table = pdf.NewTableLayout(20, 40, 21, 1)
|
|
} else {
|
|
table = pdf.NewTableLayout(20, 20, 21, 1)
|
|
}
|
|
table.AddColumn("#", 30, "left")
|
|
table.AddColumn("Name", 170, "left")
|
|
table.AddColumn("Fächer", 340, "left")
|
|
|
|
for i := tablePageIndex; i < tablePageIndex+tablePageLength; i += 1 {
|
|
if i >= len(tableEntries) {
|
|
break
|
|
}
|
|
table.AddRow(tableEntries[i])
|
|
}
|
|
|
|
table.DrawTable()
|
|
|
|
tablePageIndex += tablePageLength
|
|
|
|
pdf.SetXY(573, 815)
|
|
pdf.Cell(nil, fmt.Sprintf("%d", int(i+1)))
|
|
}
|
|
|
|
// 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,
|
|
// })
|
|
|
|
// Finish document
|
|
pdf.WritePdf("vvliste.pdf")
|
|
}
|