package controllers import ( "fmt" "log" "net/http" "strconv" "github.com/jung-kurt/gofpdf" "github.com/labstack/echo/v4" ) func (c *Controller) ExportBewertungenRoute(ctx echo.Context) error { log.Println("Exporting") pdf := gofpdf.New("P", "mm", "A4", "") pdf.AddPage() pdf.SetFont("Arial", "B", 12) pdf.CellFormat(27, 10, "Vorname", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "Nachname", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "HV-Punkte", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "HV-Note", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "LV-Punkte", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "LV-Note", "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, "Gesamtnote", "1", 0, "", false, 0, "") pdf.Ln(-1) pdf.SetFont("Arial", "", 11) for _, bewertung := range *c.Bewertungen { pdf.CellFormat(27, 10, bewertung.Vorname, "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, bewertung.Nachname, "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.HvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.HvNote), 10), "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.LvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.LvNote), 10), "1", 0, "", false, 0, "") pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.GesamtNote), 10), "1", 0, "", false, 0, "") pdf.Ln(-1) } err := pdf.OutputFileAndClose("bewertungen.pdf") if err != nil { fmt.Println("Fehler beim Exportieren der Bewertungen:", err) return err } return ctx.HTML(http.StatusOK, "Export beendet") }