【问题标题】:wkhtmltopdf not found - Golang Ubuntuwkhtmltopdf not found - Golang Ubuntu
【发布时间】:2022-12-27 17:01:02
【问题描述】:

After trying lot of solutions for this error, I am posting this issue here. I have written a method which converts html to pdf and returns pdf bytes as output.

import (
"bytes"
"github.com/SebastiaanKlippert/go-wkhtmltopdf" 
)

func HtmlToPdf(htmlData *string) ([]byte, error) {
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
    return nil, err
}
pdfg.AddPage(wkhtmltopdf.NewPageReader(bytes.NewReader([]byte(*htmlData))))
//nolint: gomnd
pdfg.Dpi.Set(600)
jb, err := pdfg.ToJSON()
if err != nil {
    return nil, err
}
pdfgFromJSON, err := wkhtmltopdf.NewPDFGeneratorFromJSON(bytes.NewReader(jb))
if err != nil {
    return nil, err
}

err = pdfgFromJSON.Create()
if err != nil {
    return nil, err
}
pdfBytes := pdfgFromJSON.Bytes()

return pdfBytes, nil }

Calling this method returns errorwkhtmltopdf not foundI have tried the following solutions

  1. which wkhtmltopdf /usr/local/bin/wkhtmltopdf and then setting the WKHTMLTOPDF_PATH: /usr/local/bin/wkhtmltopdf in environment section of my code

  2. Using setPath at the top of HtmlToPdf Method like

    wkhtmltopdf.SetPath("/usr/local/bin/wkhtmltopdf")

    In this case the error changes to fork/exec /usr/local/bin/wkhtmltopdf: no such file or directory

    1. Also tried after moving the wkhtml files to /usr/local/go/bin/ and using path /usr/local/go/bin/wkhtmltopdf

    2. Converting any url to pdf using command line also works fine.

    Note : Hitting wkhtmltopdf --version in terminal gives wkhtmltopdf 0.12.6 (with patched qt) and package is installed using go get github.com/SebastiaanKlippert/go-wkhtmltopdf

    Any other solutions?

【问题讨论】:

  • instead of setting PATH as /usr/local/go/bin/wkhtmltopdf try setting it as /usr/local/go/bin
  • note that WKHTMLTOPDF_PATH should point to directory not executable
  • Pointed the WKHTMLTOPDF_PATH to /usr/local/bin and printed the final path which is /usr/local/bin/wkhtmltopdf . File is present at this path still my method is returning the same error wkhtmltopdf not found

标签: go wkhtmltopdf


【解决方案1】:

hello in my case u should install wkhtmltopdf ,but if u are using MacOS so just install on terminal

brew install wkhtmltopdf

and make sure path directory same like you installed wkhtmltopdf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2016-06-30
    • 2022-10-22
    • 2016-09-02
    • 1970-01-01
    相关资源
    最近更新 更多