Closed chilarai closed 2 years ago
I figured out that if I pass bytes.NewBuffer
in converter.Run()
instead of outFile
, I get a consistent output. So I changed the pdf generation block from
// Convert objects and save the output PDF document.
outFile, err := os.Create(common.CONST_TMPPDF_FOLDER + "out_" + filename + ".pdf")
if err != nil {
log.Println(err)
}
defer outFile.Close()
if err := converter.Run(outFile); err != nil {
log.Println(err)
}
TO
return converter.Run(out)
...
// Do Remember to serve the file later
w.Header().Set("Content-Disposition", "attachment; filename=download.pdf")
w.Header().Set("Content-Type", "application/pdf")
if _, err := io.Copy(w, out); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
as described in https://github.com/adrg/go-wkhtmltopdf/blob/master/examples/http-server/main.go. Also, I created a new server to avoid thread related issues in pdf generation
Hi @chilarai. Did that solve the problems your were having? Can this issue be closed?
Yes thats it. Thanks
I am using the code below to generate my pdf using the library. The code executes appropriately. However, most of the time I lose my HTML formatting or even data in many cases. What could be the issue? Could this be memory related?
Note: My HTML has some css and js