【问题标题】:Passing arguments to wkhtmltopdf using GoLang使用 GoLang 将参数传递给 wkhtmltopdf
【发布时间】:2017-12-19 05:03:11
【问题描述】:

我正在尝试开发一个小应用程序来使用 wkhtmltopdf 和 GoLang 将 html 转换为 pdf。但是当我尝试向它传递参数时,退出状态为 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)

cmd 和 args 的输出

cmd: &{/path/wkhtmltopdf [/path/wkhtmltopdf --page-height 420mm --page-width 297mm /path/src/edit.html /path/src/edit.pdf] [] [] false [] [] [ ] [] }

参数[--page-height 420mm --page-width 297mm /path/src/edit.html /path/src/edit.pdf]

【问题讨论】:

    标签: go wkhtmltopdf


    【解决方案1】:

    试试这个方法,你必须用你的替换路径

    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)
    }
    

    如果好的话,可以加上 --page 参数

    【讨论】:

      【解决方案2】:

      您可以对 wkhtmltopdf 使用 Go 绑定。检查this

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 2018-12-13
        • 1970-01-01
        • 1970-01-01
        • 2022-01-27
        相关资源
        最近更新 更多