slice out of bound
Opened this issue · 2 comments
afzalabbasi commented
c := wkhtmltoimage.ImageOptions{BinaryPath: "-",Input: "/templates/email.gohtml", Format: "png"}
out, err := wkhtmltoimage.GenerateImage(&c)
if err!=nil{
fmt.Println(err.Error())
}
f, _ := os.Create("/templates/example.png")
defer f.Close()
n2, _ := f.Write(out)
fmt.Printf("wrote %d bytes\n", n2)
i got slice out of bound error can someone please me help me why i got this
rajkumarairlift commented
i also get some error
html := "
example
"// BinaryPath:"/usr/local/bin/wkhtmltoimage"
c := wkhtmltoimage.ImageOptions{Input:"-", Format: "png", Output: "example.png", Html: html,BinaryPath:"/usr/local/bin/wkhtmltoimage"}
k,err:=wkhtmltoimage.GenerateImage(&c)
if err!=nil{
fmt.Println(err)
}
fmt.Println(k)
yusrenaltair commented
Edited:
Turns Out in GenerateImage function
line 68
output, err := cmd.CombinedOutput()
return empty byte slice
So trimmed := cleanupOutput(output, options.Format)
will produce unhandled error
I make a little modification
//.....
output, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}
if len(output) > 0 {
trimmed := cleanupOutput(output, options.Format)
return trimmed, nil
}
return nil, nil
//....
My Specs : Ubuntu 20.3, wktmltopdf wkhtmltox_0.12.6-1.focal_amd64.deb; Go v1.18.3