go-wkhtmltopdf转html为pdf:
go get -u github.com/SebastiaanKlippert/go-wkhtmltopdf
vi /etc/profile
export GOPATH=/usr/lib/go/bin
:wq
source /etc/profile
vi a1.go
package main
import (
"fmt"
"log"
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
func main() {
// Create new PDF generator
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
log.Fatal(err)
}
url := "http://google.com/"
pdfg.AddPage(wkhtmltopdf.NewPage(url))
// PDFط³
err = pdfg.Create()
if err != nil {
log.Fatal(err)
}
// ³
err = pdfg.WriteFile("./google.pdf")
if err != nil {
log.Fatal(err)
}
fmt.Println("tada!")
}
go run a1.go
有疑问加站长微信联系(非本文作者)