-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
84 lines (66 loc) · 1.88 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
76
77
78
79
80
81
82
83
84
package main
import (
"strings"
"time"
pdfjet "github.com/edragoev1/pdfjet/src"
"github.com/edragoev1/pdfjet/src/compliance"
"github.com/edragoev1/pdfjet/src/contents"
"github.com/edragoev1/pdfjet/src/letter"
)
// Example47 -- TODO:
func Example47() {
pdf := pdfjet.NewPDFFile("Example_47.pdf", compliance.PDF15)
f1 := pdfjet.NewFontFromFile(pdf, "fonts/OpenSans/OpenSans-Regular.ttf.stream")
f2 := pdfjet.NewFontFromFile(pdf, "fonts/OpenSans/OpenSans-Italic.ttf.stream")
f1.SetSize(12.0)
f2.SetSize(12.0)
image1 := pdfjet.NewImageFromFile(pdf, "images/AU-map.png")
image1.ScaleBy(0.50)
image2 := pdfjet.NewImageFromFile(pdf, "images/HU-map.png")
image2.ScaleBy(0.50)
page := pdfjet.NewPage(pdf, letter.Portrait)
image1.SetLocation(20.0, 20.0)
image1.DrawOn(page)
image2.SetLocation(
page.GetWidth()-(image2.GetWidth()+20.0),
page.GetHeight()-(image2.GetHeight()+20.0))
image2.DrawOn(page)
paragraphs := make([]*pdfjet.TextLine, 0)
contents := contents.OfTextFile("data/austria_hungary.txt")
textLines := strings.Split(contents, "\n\n")
for _, textLine := range textLines {
paragraphs = append(paragraphs, pdfjet.NewTextLine(f1, textLine))
}
xPos := float32(20.0)
yPos := float32(250.0)
width := float32(180.0)
height := float32(315.0)
frame := pdfjet.NewTextFrame(paragraphs)
frame.SetLocation(xPos, yPos)
frame.SetWidth(width)
frame.SetHeight(height)
frame.SetDrawBorder(true)
frame.DrawOn(page)
xPos += 200.0
if frame.IsNotEmpty() {
frame.SetLocation(xPos, yPos)
frame.SetWidth(width)
frame.SetHeight(height)
frame.SetDrawBorder(false)
frame.DrawOn(page)
}
xPos += 200.0
if frame.IsNotEmpty() {
frame.SetLocation(xPos, yPos)
frame.SetWidth(width)
frame.SetHeight(height)
frame.SetDrawBorder(true)
frame.DrawOn(page)
}
pdf.Complete()
}
func main() {
start := time.Now()
Example47()
pdfjet.PrintDuration("Example_47", time.Since(start))
}