add PDF export

This commit is contained in:
Michael Stapelberg
2020-11-22 22:50:06 +01:00
parent 950f332cca
commit 014c819560
4 changed files with 556 additions and 1 deletions

View File

@@ -103,11 +103,12 @@ func logic() error {
if format != "png" &&
format != "svg" &&
format != "pdf" &&
format != "txt" &&
format != "html" &&
format != "wv" &&
format != "eps" {
msg := fmt.Sprintf("format (%q) must be one of png, svg, txt or html", format)
msg := fmt.Sprintf("format (%q) must be one of png, svg, pdf, eps, txt or html", format)
log.Printf("%s %s", prefix, msg)
http.Error(w, msg, http.StatusBadRequest)
return
@@ -158,6 +159,17 @@ func logic() error {
w.Header().Add("Content-Type", "image/svg+xml")
case "pdf":
var err error
b, err = bill.EncodeToPDF()
if err != nil {
log.Printf("%s %s", prefix, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/pdf")
case "eps":
var err error
b, err = bill.EncodeToEPS()