Skip to content

Go for wkhtmltopdf - Convert HTML to PDF using Webkit (fasthttp template)

License

Notifications You must be signed in to change notification settings

myussufz/html2pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html2pdf

html2pdf use wkhtmltopdf to generate PDF. It wrapper of the wkhtmltopdf using fasthttp template for html render.

This repo still under development. We accept any pull request. ^_^

Installation

  // dependency
  $ go get github.com/magicwebes/html2pdf
  $ go get github.com/valyala/fasttemplate

  // Downloading wkhtmltopdf from this website and install to the computer or server
  https://wkhtmltopdf.org/downloads.html

Quick Start

Convert html file to pdf and download

  filepath := "public/views/index.html"
  data := map[string]interface{}{
    "message": "hello",
  }
  outputPath := "public/views/index.pdf"

  if err := html2pdf.ParseHTML(filepath, data).ToFile(outputPath); err != nil {
      log.Println("error", err)
  }

Advance Usage

  filepath := "public/views/data.html"
  data := map[string]interface{}{
    "message": "hello", // pass data to html file
  }
  outputPath := "public/views/data.pdf"

  if err := html2pdf.ParseHTML(filepath, data).
    SetConfig(&html2pdf.Config{
        Orientation: html2pdf.OrientationLandscape,
        PageSize: html2pdf.PageSizeA4,
    }).
    ToFile(outputPath); err != nil {
      log.Println("error", err)
  }

About

Go for wkhtmltopdf - Convert HTML to PDF using Webkit (fasthttp template)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages