GoHTMLtoPDF Converter
What it is?
It is a repository, integrating which one can offer HTML to PDF Conversion to their customers.
Prerequisite
Install wkhtmltopdf using below command
-
Download - for Windows 64bit
-
Download - for Windows 32bit
-
sudo apt install wkhtmltopdf
- for Ubuntu
-
brew install Caskroom/cask/wkhtmltopdf
- For Mac
URL to PDF steps to follow
Create go file - main.go
package main
import (
"github.com/shamim4s/gohtmltopdf"
)
func main() {
err := gohtmltopdf.UrltoPdf("https://google.com", "google.pdf")
if err != nil {
log.Fatal(err)
}
}
Run below command
- go run main.go
Parse HTML to PDF Steps to Follow
-
Create a sample HTML file inside of your project.
-
Get go package using the below command for parsing the HTMl template.
go get github.com/shamim4s/gohtmltopdf
-
Get another go package for converting this html parse data to pdf using the below command.
-
Run below command
###The previous version of golang was deprecated and not supporting the converter library so dependencies are updated with the new updates.
#Steps by step:
- Install
golang (1.16)
- Check
go version
(Make Sure it is latest = 1.16)
After finish above steps, You can generate pdf file from html.
NOTES: The pdf will be generated in the storage directory. Don't forget to mention your html and pdf path details inside your code. If you want to generate pdf for static data then it is not mandatory to generate another html for clone data. Use that same sample html inside the code.
LICENSE!
Golang HTML to PDF Converter is MIT-licensed
Let us know!
We’d be really happy if you sent us links to your projects where you use our component. Just send an email to me@shamim.app And do let us know if you have any questions or suggestion regarding our work.