Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fork/exec /usr/local/bin/wkhtmltopdf: exec format error #7

Open
voducdat opened this issue Dec 14, 2021 · 2 comments
Open

fork/exec /usr/local/bin/wkhtmltopdf: exec format error #7

voducdat opened this issue Dec 14, 2021 · 2 comments

Comments

@voducdat
Copy link

I run: go run main.go

//generate pdf function
func (r *RequestPdf) GeneratePDF(pdfPath string) (bool, error) {
t := time.Now().Unix()
// write whole the body

if _, err := os.Stat("cloneTemplate/"); os.IsNotExist(err) {
	errDir := os.Mkdir("cloneTemplate/", 0777)
	if errDir != nil {
		log.Fatal(errDir)
	}
}
err1 := ioutil.WriteFile("cloneTemplate/"+strconv.FormatInt(int64(t), 10)+".html", []byte(r.body), 0644)
if err1 != nil {
	panic(err1)
}

f, err := os.Open("cloneTemplate/" + strconv.FormatInt(int64(t), 10) + ".html")
if f != nil {
	defer f.Close()
}
if err != nil {
	log.Fatal(err)
}

pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
	fmt.Println("===================1===================")
	fmt.Println(err)
	log.Fatal(err)
}

pdfg.AddPage(wkhtmltopdf.NewPageReader(f))

pdfg.PageSize.Set(wkhtmltopdf.PageSizeA4)

pdfg.Dpi.Set(300)

err = pdfg.Create()
if err != nil {
	fmt.Println("===================2===================")
	fmt.Println(err)
	log.Fatal(err)
}

err = pdfg.WriteFile(pdfPath)
if err != nil {
	fmt.Println("===================3===================")
	fmt.Println(err)
	log.Fatal(err)
}

dir, err := os.Getwd()
if err != nil {
	panic(err)
}

defer os.RemoveAll(dir + "/cloneTemplate")

return true, nil

}

@adityasinh-mi
Copy link
Collaborator

Hello @voducdat,

  • It looks like you're encountering an error when running your Go code that involves generating a PDF using wkhtmltopdf. The error message "fork/exec /usr/local/bin/wkhtmltopdf: exec format error" suggests that there is an issue with the executable file for wkhtmltopdf.

  • To fix this issue, you may want to check that wkhtmltopdf is installed correctly and that its executable file has the correct permissions. You may also want to ensure that you have the correct version of wkhtmltopdf installed and that it is compatible with your operating system. Additionally, you could try specifying the full path to the wkhtmltopdf executable file in your code to ensure that it is correctly referenced.

I hope this helps! Let us know if you have any further questions or concerns.

@html2any
Copy link

I just wrote a library with the help of gpt, which is much more efficient for simple HTML: https://github.com/html2any/layout. You can try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants