-
Notifications
You must be signed in to change notification settings - Fork 0
/
html2pdf.go
48 lines (38 loc) · 916 Bytes
/
html2pdf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log"
wkhtmltopdf "github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
func main() {
// Create new PDF generator
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
log.Fatal(err)
}
// Set global options
pdfg.Dpi.Set(300)
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
pdfg.Grayscale.Set(false)
// Create a new input page from an URL
page := wkhtmltopdf.NewPage("http://localhost:8081/public/certif.html")
// Set options for this page
page.FooterRight.Set("[page]")
page.FooterCenter.Set("Issuer Copy")
page.FooterFontSize.Set(10)
page.Zoom.Set(0.95)
// Add to document
pdfg.AddPage(page)
// Create PDF document in internal buffer
err = pdfg.Create()
if err != nil {
log.Fatal(err)
}
// Write buffer contents to file on disk
err = pdfg.WriteFile("./certif.pdf")
if err != nil {
log.Fatal(err)
}
fmt.Println("Done")
// Output: Done
}