Commit 96470ca0 authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

Start Rewrite to use athenapdf service instead

parent 0e2b78f8
Pipeline #6888 failed with stages
in 1 minute and 5 seconds
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
"os"
"os/exec"
"strings"
wkhtml "github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
type Printer struct {
......@@ -40,7 +42,8 @@ func main() {
defer lfile.Close()
var mapping map[string]Printer
cfgFile, err := os.Open("/usr/lib/cups/backend/kohaprinter_mapping.json")
mFile := "/usr/lib/cups/backend/kohaprinter_mapping.json"
cfgFile, err := os.Open(mFile)
if err != nil {
fail(err)
}
......@@ -81,11 +84,7 @@ func main() {
}
// All good, lets render
pdfg, err := wkhtml.NewPDFGenerator()
if err != nil {
fail(err)
}
// switch to athenapdf
var data []byte
// Read job data from file or stdin
if os.Args[6] != "" {
......@@ -110,39 +109,63 @@ func main() {
defer os.Remove(tmpf.Name())
var args []string
pdfg.Dpi.Set(300)
pdfg.MarginLeft.Set(2)
pdfg.MarginRight.Set(2)
// Post file to localhost athenapdf
var b bytes.Buffer
w := multipart.NewWriter(&b)
fw, err := w.CreateFormFile("file", "/tmp/tmp.html")
if err != nil {
fail(err)
}
fw.Write(data)
conv := `{"conversion": {"mime_type": {"text/html"}}`
_ = w.WriteField("process", conv)
w.Close()
req, err := http.NewRequest("POST", "http://localhost:8089/convert?auth=arachnys-weaver", &b)
if err != nil {
fail(err)
}
req.Header.Set("Content-Type", w.FormDataContentType())
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fail(err)
}
io.Copy(tmpf, resp.Body)
var args []string
/*
pdfg.Dpi.Set(300)
pdfg.MarginLeft.Set(2)
pdfg.MarginRight.Set(2)
*/
switch prType {
case "receipt":
pdfg.PageWidth.Set(80)
pdfg.PageHeight.Set(300)
//pdfg.PageWidth.Set(80)
//pdfg.PageHeight.Set(300)
args = []string{"-d", printer.Receipt, tmpf.Name()}
case "label":
pdfg.PageWidth.Set(50)
pdfg.PageHeight.Set(99)
//pdfg.PageWidth.Set(50)
//pdfg.PageHeight.Set(99)
args = []string{"-d", printer.Label, tmpf.Name()}
default:
// no sensible default
args = []string{"-d", "dummy", tmpf.Name()}
}
pdfg.NoPdfCompression.Set(true)
pdfg.AddPage(wkhtml.NewPageReader(strings.NewReader(string(data))))
/* pdfg.NoPdfCompression.Set(true)
pdfg.AddPage(wkhtml.NewPageReader(strings.NewReader(string(data))))
err = pdfg.Create()
if err != nil {
fail(err)
}
err = pdfg.Create()
if err != nil {
fail(err)
}
if _, err := tmpf.Write(pdfg.Bytes()); err != nil {
fail(err)
}
if err := tmpf.Close(); err != nil {
fail(err)
}
if _, err := tmpf.Write(pdfg.Bytes()); err != nil {
fail(err)
}
if err := tmpf.Close(); err != nil {
fail(err)
}*/
Log.Printf("[INFO ] ARGS: %s\n", args)
out, err := exec.Command("lp", args...).Output()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment