commit 9d838ad9ec74822c51ad50dcdc6ff119847878e4 Author: denizk0461 Date: Fri Apr 10 16:26:03 2026 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62572da --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Code coverage profiles and other test artifacts +*.out +coverage.* +*.coverprofile +profile.cov + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env + +# Editor/IDE +# .idea/ +# .vscode/ + +*.pdf +*.csv \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..295a9d6 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module stugago-vvlist + +go 1.25.8 + +require ( + github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect + github.com/pkg/errors v0.8.1 // indirect + github.com/signintech/gopdf v0.36.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bb9b32d --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no= +github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/signintech/gopdf v0.36.0 h1:/7gPwoLtlNv5tPNpYuo3T3z0mWgo62pTrCvVNAiOo2Q= +github.com/signintech/gopdf v0.36.0/go.mod h1:d23eO35GpEliSrF22eJ4bsM3wVeQJTjXTHq5x5qGKjA= diff --git a/inter.ttf b/inter.ttf new file mode 100644 index 0000000..ce097c8 Binary files /dev/null and b/inter.ttf differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..91352bf --- /dev/null +++ b/main.go @@ -0,0 +1,121 @@ +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") +} \ No newline at end of file