diff --git a/index.html b/index.html index deb9e4a..2efd40c 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,14 @@ +

Create Generic Label

+
+ + +

+ +
+ \ No newline at end of file diff --git a/main.go b/main.go index 05bfcfb..015bc7b 100644 --- a/main.go +++ b/main.go @@ -76,6 +76,10 @@ func main() { createDnhLabelHandler(w, r, ep) }) + http.HandleFunc("/create_generic_label", func(w http.ResponseWriter, r *http.Request) { + createGenericLabelHandler(w, r, ep) + }) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "index.html") }) @@ -127,4 +131,36 @@ func createDnhLabelHandler(w http.ResponseWriter, r *http.Request, ep *escpos.Es ep.Cut() ep.End() w.WriteHeader(http.StatusOK) +} + + +func createGenericLabelHandler(w http.ResponseWriter, r *http.Request, ep *escpos.Escpos) { + if r.Method != http.MethodPost { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + + text := r.FormValue("text") + // Check if name is blank + if text == "" { + http.Error(w, "Text cannot be blank", http.StatusBadRequest) + return + } + + + // Here you can add the logic for creating a label using the POST data + ep.Init() + ep.WriteRaw(pageMode()) + ep.WriteRaw(pageDirection(1)) + ep.WriteRaw(pagePrintArea(0, 0, int(math.Round((29.0/80.0)*512)), 850)) + ep.WriteRaw(offsetY(30)) + ep.SetFontSize(1, 1) + ep.Write("Technologia Incognita\n") + ep.WriteRaw(offsetY(35)) + ep.SetFontSize(1, 2) + ep.Write(text) + ep.WriteRaw([]byte{12}) // FF: in Page mode, prints all the data in the print buffer collectively and switches from Page mode to Standard mode. + ep.Cut() + ep.End() + w.WriteHeader(http.StatusOK) } \ No newline at end of file