-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
75 lines (63 loc) · 1.66 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"time"
pdfjet "github.com/edragoev1/pdfjet/src"
"github.com/edragoev1/pdfjet/src/a4"
"github.com/edragoev1/pdfjet/src/color"
"github.com/edragoev1/pdfjet/src/compliance"
)
/**
* Example_18.go
* This example shows how to write "Page X of N" footer on every page.
*/
func Example18() {
pdf := pdfjet.NewPDFFile("Example_18.pdf", compliance.PDF15)
font := pdfjet.NewFontFromFile(pdf, "fonts/RedHatText/RedHatText-Regular.ttf.stream")
font.SetSize(12.0)
pages := make([]*pdfjet.Page, 0)
page := pdfjet.NewPageDetached(pdf, a4.Portrait)
box := pdfjet.NewBox()
box.SetLocation(50.0, 50.0)
box.SetSize(100.0, 100.0)
box.SetColor(color.Red)
box.SetFillShape(true)
box.DrawOn(page)
pages = append(pages, page)
page = pdfjet.NewPageDetached(pdf, a4.Portrait)
box = pdfjet.NewBox()
box.SetLocation(50.0, 50.0)
box.SetSize(100.0, 100.0)
box.SetColor(color.Green)
box.SetFillShape(true)
box.DrawOn(page)
pages = append(pages, page)
page = pdfjet.NewPageDetached(pdf, a4.Portrait)
box = pdfjet.NewBox()
box.SetLocation(50.0, 50.0)
box.SetSize(100.0, 100.0)
box.SetColor(color.Blue)
box.SetFillShape(true)
box.DrawOn(page)
pages = append(pages, page)
for i := 0; i < len(pages); i++ {
page := pages[i]
footer := "Page " + fmt.Sprint(i+1) + " of " + fmt.Sprint((len(pages)))
page.SetBrushColor(color.Black)
page.DrawString(
font,
nil,
footer,
(page.GetWidth()-font.StringWidth(font, footer))/2.0,
(page.GetHeight() - 5.0))
}
for i := 0; i < len(pages); i++ {
pdf.AddPage(pages[i])
}
pdf.Complete()
}
func main() {
start := time.Now()
Example18()
pdfjet.PrintDuration("Example_18", time.Since(start))
}