-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.go
More file actions
37 lines (34 loc) · 762 Bytes
/
export.go
File metadata and controls
37 lines (34 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"log"
"time"
"github.com/go-pdf/fpdf"
)
func createPDF(fn string, timeframe string) {
var data []string
switch timeframe {
case "month":
data = monthReport(fn, settings)
case "week":
data = weekReport(fn, settings)
default:
data = weekReport(fn, settings)
}
day := time.Now().Format(time.DateOnly)
outfile := day + ".pdf"
pdf := fpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "", 10)
leftMargin, _, rightMargin, _ := pdf.GetMargins()
pageWidth, _ := pdf.GetPageSize()
pageWidth -= leftMargin + rightMargin
for _, element := range data {
// X, Y, TEXT
pdf.WriteAligned(pageWidth, 35, element, "L")
pdf.Ln(5)
}
err := pdf.OutputFileAndClose(outfile)
if err != nil {
log.Fatal(err)
}
}