Golang HTML to PDF Converter

Overview

Golang HTML to PDF Converter

License: MIT

For reading any document, one prefers PDF format over any other formats as it is considered as a standard format for any document in our day to day life. We often come across converting any form details or previews on the website in the form of HTML to PDF. For GoLang, understanding such usability, Developers at Mindinventory made an effort for making one HTML to PDF Converter which can be used for converting HTML content to PDF.

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

  • sudo apt install wkhtmltopdf - for Ubuntu
  • brew install Caskroom/cask/wkhtmltopdf - For Mac

Steps to Follow

  1. Create a sample HTML file inside of your project.

  2. Get go package using the below command for parsing the HTMl template.

    • go get github.com/SebastiaanKlippert/go-wkhtmltopdf
  3. Get another go package for converting this html parse data to pdf using the below command.

    • go get html/template
  4. Run below command

    • go run main.go

###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)
  • go mod vendor
  • go build

##To Run the project:

  • go run main.go

Update project dependencies

  • go get github.com/SebastiaanKlippert/go-wkhtmltopdf v1.6.1
  • go get html/template

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 [email protected] And do let us know if you have any questions or suggestion regarding our work.

Issues
  • Compilation Issue

    Compilation Issue

    $ go build -ldflags=-s . main.go:4:2: cannot find package "Golang-HTMLTOPDF-Converter/pdfGenerator" in any of: c:\go\src\vendor\Golang-HTMLTOPDF-Converter\pdfGenerator (vendor tree) c:\go\src\Golang-HTMLTOPDF-Converter\pdfGenerator (from $GOROOT) C:\Users\0wner\go\src\Golang-HTMLTOPDF-Converter\pdfGenerator (from $GOPATH)

    How do proceed?

    Thanks in advance.

    opened by pedroalbanese 0
  • fork/exec /usr/local/bin/wkhtmltopdf: exec format error

    fork/exec /usr/local/bin/wkhtmltopdf: exec format error

    I run: go run main.go

    //generate pdf function func (r *RequestPdf) GeneratePDF(pdfPath string) (bool, error) { t := time.Now().Unix() // write whole the body

    if _, err := os.Stat("cloneTemplate/"); os.IsNotExist(err) {
    	errDir := os.Mkdir("cloneTemplate/", 0777)
    	if errDir != nil {
    		log.Fatal(errDir)
    	}
    }
    err1 := ioutil.WriteFile("cloneTemplate/"+strconv.FormatInt(int64(t), 10)+".html", []byte(r.body), 0644)
    if err1 != nil {
    	panic(err1)
    }
    
    f, err := os.Open("cloneTemplate/" + strconv.FormatInt(int64(t), 10) + ".html")
    if f != nil {
    	defer f.Close()
    }
    if err != nil {
    	log.Fatal(err)
    }
    
    pdfg, err := wkhtmltopdf.NewPDFGenerator()
    if err != nil {
    	fmt.Println("===================1===================")
    	fmt.Println(err)
    	log.Fatal(err)
    }
    
    pdfg.AddPage(wkhtmltopdf.NewPageReader(f))
    
    pdfg.PageSize.Set(wkhtmltopdf.PageSizeA4)
    
    pdfg.Dpi.Set(300)
    
    err = pdfg.Create()
    if err != nil {
    	fmt.Println("===================2===================")
    	fmt.Println(err)
    	log.Fatal(err)
    }
    
    err = pdfg.WriteFile(pdfPath)
    if err != nil {
    	fmt.Println("===================3===================")
    	fmt.Println(err)
    	log.Fatal(err)
    }
    
    dir, err := os.Getwd()
    if err != nil {
    	panic(err)
    }
    
    defer os.RemoveAll(dir + "/cloneTemplate")
    
    return true, nil
    

    }

    opened by voducdat 0
Owner
MindInventory
MindInventory works with Enterprises, Startups, and Agencies since 2011 providing web, mobile app development, enterprise mobility solutions & DevOps services.
MindInventory
Ensembles of decision trees in go/golang.

CloudForest Google Group Fast, flexible, multi-threaded ensembles of decision trees for machine learning in pure Go (golang). CloudForest allows for a

Ryan Bressler 711 Jun 21, 2022
Genetic Algorithms library written in Go / golang

Description Genetic Algorithms for Go/Golang Install $ go install git://github.com/thoj/go-galib.git Compiling examples: $ git clone git://github.com

Thomas Jager 192 May 26, 2022
Golang Genetic Algorithm

goga Golang implementation of a genetic algorithm. See ./examples for info on how to use the library. Overview Goga is a genetic algorithm solution wr

null 164 Jun 18, 2022
Golang Neural Network

Varis Neural Networks with GO About Package Some time ago I decided to learn Go language and neural networks. So it's my variation of Neural Networks

Artem Filippov 44 Mar 20, 2022
Golang implementation of the Paice/Husk Stemming Algorithm

##Golang Implementation of the Paice/Husk stemming algorithm This project was created for the QUT course INB344. Details on the algorithm can be found

Aaron Groves 28 Jan 23, 2022
A high-performance timeline tracing library for Golang, used by TiDB

Minitrace-Go A high-performance, ergonomic timeline tracing library for Golang. Basic Usage package main import ( "context" "fmt" "strcon

TiKV Project 43 May 5, 2022
Gota: DataFrames and data wrangling in Go (Golang)

Gota: DataFrames, Series and Data Wrangling for Go This is an implementation of DataFrames, Series and data wrangling methods for the Go programming l

null 2.2k Jun 26, 2022
Golang k-d tree implementation with duplicate coordinate support

Golang k-d tree implementation with duplicate coordinate support

DownFlux 45 Apr 13, 2022
Another AOC repo (this time in golang!)

advent-of-code Now with 100% more golang! (It's going to be a long advent of code...) To run: Get your data for a given year/day and copy paste it to

Jon Schwartz 0 Dec 14, 2021
Go (Golang) encrypted deep learning library; Fully homomorphic encryption over neural network graphs

DC DarkLantern A lantern is a portable case that protects light, A dark lantern is one who's light can be hidden at will. DC DarkLantern is a golang i

Raven 1 Dec 2, 2021
Clean Architecture With Golang

Clean Architecture With Golang When init a new project go mod init github.com/samuelterra22/clean-architecture-go Run testes go test ./... Generate a

Samuel Terra 1 Dec 14, 2021
TFKG - A Tensorflow and Keras Golang port

TFKG - A Tensorflow and Keras Golang port This is experimental and quite nasty under the hood* Support macOS: running docker container, no GPU acceler

Tim Marshall 36 Jun 10, 2022
face detction/recognization golang lib using tensorflow facenet

Golang lib for detect/recognize by tensorflow facenet Prerequest libtensorfow 1.x Follow the instruction Install TensorFlow for C facenet tenorflow sa

Prof Syd Xu 0 Oct 15, 2021
Genetic algorithms using Golang Generics

Package genetic Package genetic implements genetic algorithms using Golang's Gen

Konnor Klashinsky 2 Jun 18, 2022
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)

Go View File 在线体验地址 http://39.97.98.75:8082/view/upload (不会经常更新,保留最基本的预览功能。服务器配置较低,如果出现链接超时请等待几秒刷新重试,或者换Chrome) 目前已经完成 docker部署 (不用为运行环境烦恼) Wor

CZC 59 Jun 14, 2022
Golang PDF library for creating and processing PDF files (pure go)

UniPDF - PDF for Go UniDoc UniPDF is a PDF library for Go (golang) with capabilities for creating and reading, processing PDF files. The library is wr

UniDoc 1.6k Jun 27, 2022
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Ali Bala 441 May 15, 2022
Convert scanned image PDF file to text annotated PDF file

Jisui (自炊) This tool is PoC (Proof of Concept). Jisui is a helper tool to create e-book. Ordinary the scanned book have not text information, so you c

Takumasa Sakao 27 Apr 7, 2022
goldmark-pdf is a renderer for goldmark that allows rendering to PDF.

A PDF renderer for the goldmark markdown parser.

Stephen Afam-Osemene 85 May 10, 2022
Simple Markdown to Html converter in Go.

Markdown To Html Converter Simple Example package main import ( "github.com/gopherzz/MTDGo/pkg/lexer" "github.com/gopherzz/MTDGo/pkg/parser" "fm

Nikita Kazeka 2 Jan 29, 2022
Godown - Markdown to HTML converter made with Go

Godown Godown is a tiny-teeny utility that helps you convert your Markdown files

Kevin Suñer 0 Jan 18, 2022
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Taco de Wolff 986 Jun 22, 2022
wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion

wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion. Implements wkhtmltopdf Go bindings. It can be used to convert HTML docume

Adrian-George Bostan 111 Jun 17, 2022
Take screenshots of websites and create PDF from HTML pages using chromium and docker

gochro is a small docker image with chromium installed and a golang based webserver to interact wit it. It can be used to take screenshots of w

Christian Mehlmauer 48 Jun 12, 2022
mold your templated to HTML/ TEXT/ PDF easily.

mold mold your templated to HTML/ TEXT/ PDF easily. install go get github.com/mayur-tolexo/mold Example 1 //Todo model type Todo struct { Title stri

Mayur Das 0 Jun 7, 2019
Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text

docconv A Go wrapper library to convert PDF, DOC, DOCX, XML, HTML, RTF, ODT, Pages documents and images (see optional dependencies below) to plain tex

Search.io 959 Jun 23, 2022
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Microcosm 2.3k Jun 24, 2022
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Nelo Mitranim 4 Apr 13, 2022
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients Email clients use different rendering standards. This is

Alexey Vasiliev 18 Feb 8, 2022