golang html转成pdf,在Golang中从html创建pdf
安装go get -u github.com/SebastiaanKlippert/go-wkhtmltopdfgo version go1.9.2 linux/amd64代码import ("fmt""strings"wkhtml "github.com/SebastiaanKlippert/go-wkhtmltopdf")func main(){pdfg, err := wkhtml.New.
安装
go get -u github.com/SebastiaanKlippert/go-wkhtmltopdf
go version go1.9.2 linux/amd64
代码
import (
"fmt"
"strings"
wkhtml "github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
func main(){
pdfg, err := wkhtml.NewPDFGenerator()
if err != nil{
return
}
htmlStr := `
This is an html
from pdf to test color
`
pdfg.AddPage(wkhtml.NewPageReader(strings.NewReader(htmlStr)))
// Create PDF document in internal buffer
err = pdfg.Create()
if err != nil {
log.Fatal(err)
}
//Your Pdf Name
err = pdfg.WriteFile("./Your_pdfname.pdf")
if err != nil {
log.Fatal(err)
}
fmt.Println("Done")
}
上面的代码适用于使用适当的背景图片和嵌入式CSS样式标签在golang中将html转换为pdf
更多推荐
所有评论(0)