I am trying to develop a small app to convert html to pdf using wkhtmltopdf and GoLang. But when I try to pass arguments to it, getting an exit status of 1.
args := []string{"--page-height 420mm","--page-width 297mm","/path/src/edit.html","/path/src/edit.pdf"} fmt.Println(args) cmd := exec.Command("/home/local/ZOHOCORP/santhosh-4759/Downloads/wkhtmltox/bin/wkhtmltopdf",args...) fmt.Println(cmd)
Ouptut of cmd and args
cmd: &{/path/wkhtmltopdf [/path/wkhtmltopdf --page-height 420mm --page-width 297mm /path/src/edit.html /path/src/edit.pdf] [] [] false [] [] [] [] }
args[--page-height 420mm --page-width 297mm /path/src/edit.html /path/src/edit.pdf]
Try this way, you'll have to replace the paths with yours
args := []string{"./wkhtmltopdfTest/edit.html","./wkhtmltopdfTest/edit.pdf"}
cmd := exec.Command("/usr/local/bin/wkhtmltopdf",args...)
out,err := cmd.CombinedOutput()
if err == nil {
fmt.Printf("PDF succesfully generated")
} else {
fmt.Printf("Error: %s %s", err, out)
}
If it's good, you can add the --page arguments
You can use Go binding for wkhtmltopdf
. Check this