How to create PDF files from an HTML input in Google Go? If it is not possible yet, are there any initations that aims to solve this problem?
I'm looking for a solution like TCPDF in php.
what about gopdf (https://github.com/signintech/gopdf) or gofpdf (http://godoc.org/code.google.com/p/gofpdf).
It seems like you are looking for.
I don't think I understand your requirements. Since HTML is a markup language, it needs context to render (CSS and a screen size). Existing implementations I've seen generally open the page in a headless browser and create a PDF that way.
Personally, I would just use an existing package and shell out from Go. This one looks good; it's even recommended in this answer.
If you're really determined to implement it all in Go, check out this WebKit wrapper. I'm not sure what you'd use for generating PDFs, but but at least it's a start.
There is also this package wkhtmltopdf-go, which uses the libwkhtmltox library. I am not sure how stable it is though.
Another option is Athena. It has a microservice written in Go or it can be used as a CLI.
Installation
go get -u github.com/SebastiaanKlippert/go-wkhtmltopdf
go version go1.9.2 linux/amd64
code
import (
"fmt"
"strings"
wkhtml "github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
func main(){
pdfg, err := wkhtml.NewPDFGenerator()
if err != nil{
return
}
htmlStr := `<html><body><h1 style="color:red;">This is an html
from pdf to test color<h1><img src="http://api.qrserver.com/v1/create-qr-
code/?data=HelloWorld" alt="img" height="42" width="42"></img></body></html>`
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")
}
The Above code Works for Converting html to pdf in golang with proper background image and Embedded Css Style Tags
I'm creating an alternative lib to create PDFs in a simpler way (https://github.com/johnfercher/maroto). It uses gofpdf and have a grid system and some components like Bootstrap.
用基础库写pdf太痛苦。试试这个。/动态内容自动分页不截断、可预览、页码、目录、适配 wkhtmltopdf和chrome headless
https://gitee.com/wuxue107/bookjs-eazy