url := "" res, err := http.Get(url) if err != nil { fmt.Fprintf(os.Stderr, "fetch: %v", err) os.Exit(1) } // 读取资源数据 body: []byte body, err := ioutil.ReadAll(res.Body) fmt.Println(string(body), err) res.Body.Close() pdfg, err := wkhtml.NewPDFGenerator() fmt.Println(err) pdfg.AddPage(wkhtml.NewPageReader(strings.NewReader(string(body)))) // Create PDF document in internal buffer err = pdfg.Create() if err != nil { fmt.Println(err) } err = pdfg.WriteFile("./test.pdf") fmt.Println(err)
安装wkhtmltopdf:brew install wkhtmltopdf
linux安装:
下载文件:https://wkhtmltopdf.org/downloads.html
sudo apt-get install xfonts-encodings xfonts-utils xfonts-base xfonts-75dpi
dpkg -i wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
wkhtmltopdf -V
标签:body,err,fmt,wkhtmltopdf,pdfg,golang,html,Println,pdf From: https://www.cnblogs.com/shenxiaobin/p/16628473.html