Package htmltopdf implements wkhtmltopdf Go bindings.

htmltopdf

Package htmltopdf implements wkhtmltopdf Go bindings. It can be used to convert HTML documents to PDF files. The package does not use the wkhtmltopdf binary. Instead, it uses the wkhtmltox library directly.

Usage

package main

import (
  "log"
  "os"

  "github.com/digitaldata-cz/htmltopdf"
)

func main() {
  htmltopdf.Init()
  defer htmltopdf.Destroy()

  // Create object from file.
  object1, err := htmltopdf.NewObject("sample1.html")
  if err != nil {
    log.Fatal(err)
  }
  object1.Header.ContentCenter = "[title]"
  object1.Header.DisplaySeparator = true

  // Create object from URL.
  object2, err := htmltopdf.NewObject("https://google.com")
  if err != nil {
    log.Fatal(err)
  }
  object2.Footer.ContentLeft = "[date]"
  object2.Footer.ContentCenter = "Sample footer information"
  object2.Footer.ContentRight = "[page]"
  object2.Footer.DisplaySeparator = true

  // Create object from reader.
  inFile, err := os.Open("sample2.html")
  if err != nil {
    log.Fatal(err)
  }
  defer inFile.Close()

  object3, err := htmltopdf.NewObjectFromReader(inFile)
  if err != nil {
    log.Fatal(err)
  }
  object3.Zoom = 1.5
  object3.TOC.Title = "Table of Contents"

  // Create converter.
  converter, err := htmltopdf.NewConverter()
  if err != nil {
    log.Fatal(err)
  }
  defer converter.Destroy()

  // Add created objects to the converter.
  converter.Add(object1)
  converter.Add(object2)
  converter.Add(object3)

  // Set converter options.
  converter.Title = "Sample document"
  converter.PaperSize = htmltopdf.A4
  converter.Orientation = htmltopdf.Landscape
  converter.MarginTop = "1cm"
  converter.MarginBottom = "1cm"
  converter.MarginLeft = "10mm"
  converter.MarginRight = "10mm"

  // Convert objects and save the output PDF document.
  outFile, err := os.Create("out.pdf")
  if err != nil {
    log.Fatal(err)
  }
  defer outFile.Close()

  if err := converter.Run(outFile); err != nil {
    log.Fatal(err)
  }
}

For more information see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt

LICENSE

MIT

Similar Resources

Go-wk - PDF Generation API with wkhtmltopdf

Simple PDF Generation API with wkhtmltopdf Quick start Clone the repo locally an

Jan 25, 2022

[DEPRECATED] Go package authcookie implements creation and verification of signed authentication cookies.

Package authcookie import "github.com/dchest/authcookie" Package authcookie implements creation and verification of signed authentication cookies. Co

Dec 22, 2022

Package go-otp implements one-time-password generators used in 2-factor authentication systems like RSA-tokens. Currently this supports both HOTP (RFC-4226), TOTP (RFC-6238) and Base32 encoding (RFC-3548) for Google Authenticator compatibility

OTP Package go-otp implements one-time-password generators used in 2-factor authentication systems like RSA-tokens and Google Authenticator. Currently

Oct 8, 2022

Package geom implements efficient geometry types for geospatial applications.

go-geom Package geom implements efficient geometry types for geospatial applications. Key features OpenGeo Consortium-style geometries. Support for 2D

Jan 6, 2023

Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Dec 1, 2022

Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

arp Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed. Portions of this code are taken from the Go standard library. The

Dec 20, 2022

Package dhcp6 implements a DHCPv6 server, as described in RFC 3315. MIT Licensed.

dhcp6 Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed. At this time, the API is not stable, and may change over

Sep 27, 2022

Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed.

ethernet Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed. For more in

Dec 29, 2022

Package goraph implements graph data structure and algorithms.

Package goraph implements graph data structure and algorithms.

goraph Package goraph implements graph data structure and algorithms. go get -v gopkg.in/gyuho/goraph.v2; I have tutorials and visualizations of grap

Dec 20, 2022

Package cae implements PHP-like Compression and Archive Extensions.

Compression and Archive Extensions 中文文档 Package cae implements PHP-like Compression and Archive Extensions. But this package has some modifications de

Jun 16, 2022

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dec 30, 2022

Package mafsa implements Minimal Acyclic Finite State Automata in Go, essentially a high-speed, memory-efficient, Unicode-friendly set of strings.

MA-FSA for Go Package mafsa implements Minimal Acyclic Finite State Automata (MA-FSA) with Minimal Perfect Hashing (MPH). Basically, it's a set of str

Oct 27, 2022

Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

Jun 26, 2022

Random is a package written in Go that implements pseudo-random number generators for various distributions.

Random This package implements pseudo-random number generators for various distributions. For integers, there is a function for random selection from

Jul 11, 2022

Package tail implements file tailing with fsnotify.

Tail Package tail implements file tailing with fsnotify. Fork of nxadm/tail, simplified, reworked and optimized. Fully supports only posix-compatible

Nov 30, 2022

asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Jul 3, 2022

Package macho implements access to and creation of Mach-O object files.

go-macho [WIP] 🚧 Package macho implements access to and creation of Mach-O object files. Why 🤔 This package goes beyond the Go's debug/macho to: Cov

Sep 2, 2022

Provides the radix package that implements a radix tree.

go-radix Provides the radix package that implements a radix tree. The package only provides a single Tree implementation, optimized for sparse nodes.

Oct 26, 2021

Package qrcode implements a QR Code encoder

go-qrcode Package qrcode implements a QR Code encoder. A QR Code is a matrix (two-dimensional) barcode. Arbitrary content may be encoded, with URLs be

Nov 11, 2021
Related tags
Go (golang) bindings for the 0mq (zmq, zeromq) C API

NOTE: These gozmq bindings are in maintenance mode. Only critical bugs will be fixed. Henceforth I would suggest using @pebbe's actively maintained bi

Dec 9, 2022
Package notify provides an implementation of the Gnome DBus Notifications Specification.

go-notify Package notify provides an implementation of the Gnome DBus Notifications Specification. Examples Display a simple notification. ntf := noti

Dec 27, 2022
The official Go package for NSQ

go-nsq The official Go package for NSQ. Docs See godoc and the main repo apps directory for examples of clients built using this package. Tests Tests

Jan 5, 2023
A simple pubsub package for go.

Package pubsub implements a simple multi-topic pub-sub library. Install pubsub with, go get github.com/cskr/pubsub This repository is a go module and

Dec 31, 2022
Simple synchronous event pub-sub package for Golang

event-go Simple synchronous event pub-sub package for Golang This is a Go language package for publishing/subscribing domain events. This is useful to

Jun 16, 2022
Scalable package delivery logistics simulator built using SingleStore and Vectorized Redpanda
Scalable package delivery logistics simulator built using SingleStore and Vectorized Redpanda

Reference Architecture using SingleStore and Redpanda for global logistics ?? INFO: For the story behind this code (and epic dashboards), check out th

Oct 29, 2022
An opinionated package that helps you print user-friendly output messages from your Go command line applications.

github.com/eth-p/clout (Command Line Output) clout is a package that helps you print user-friendly output messages from your Go command line applicati

Jan 15, 2022
Redis as backend for Queue Package
Redis as backend for Queue Package

redis Redis as backend for Queue package Setup start the redis server redis-server start the redis cluster, see the config # server 01 mkdir server01

Oct 16, 2022
NSQ as backend for Queue Package
NSQ as backend for Queue Package

NSQ as backend for Queue Package

Jul 4, 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

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

Dec 17, 2022