dragon0023 2017-07-14 07:26
浏览 169

使用GoLang将参数传递给wkhtmltopdf

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]

  • 写回答

2条回答 默认 最新

  • dpw63348 2017-07-14 10:16
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办