2017-07-14 80 views
0

我想開發一個小型應用程序來使用wkhtmltopdf和GoLang將html轉換爲pdf。但是,當我試圖傳遞參數給它,漸漸的1使用GoLang將參數傳遞給wkhtmltopdf

ARGS退出狀態:= [] {字符串「 - 頁面高度420毫米」,「 - 頁寬297毫米」 「/path/src/edit.html","/path/src/edit.pdf」} fmt.Println(args) cmd:= exec.Command(「/ home/local/ZOHOCORP/santhosh-4759/Downloads/wkhtmltox /斌/ wkhtmltopdf」,ARGS ...) fmt.Println(CMD)

Ouptut CMD的和args

CMD: & {/路徑/ wkhtmltopdf [/路徑/ wkhtmltopdf --page高度420毫米--page寬度297毫米/path/src/edit.html /path/src/edit.pdf ] [] [] false] [] [] [] []}

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

回答

0

試試這種方式,您將不得不用你的路徑代替

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參數

0

您可以使用Go爲wkhtmltopdf結合。檢查this