Initial commit
This commit is contained in:
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@@ -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
|
||||
9
go.mod
Normal file
9
go.mod
Normal file
@@ -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
|
||||
)
|
||||
6
go.sum
Normal file
6
go.sum
Normal file
@@ -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=
|
||||
121
main.go
Normal file
121
main.go
Normal file
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user