-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
74 lines (59 loc) · 1.97 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
package main
import (
"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"
)
// Example19 draws two images and three text boxes.
func Example19() {
pdf := pdfjet.NewPDFFile("Example_19.pdf", compliance.PDF15)
f1 := pdfjet.NewFontFromFile(pdf, "fonts/OpenSans/OpenSans-Regular.ttf.stream")
f2 := pdfjet.NewFontFromFile(pdf, "fonts/Droid/DroidSansFallback.ttf.stream")
f1.SetSize(10.0)
f2.SetSize(10.0)
image1 := pdfjet.NewImageFromFile(pdf, "images/fruit.jpg")
image2 := pdfjet.NewImageFromFile(pdf, "images/ee-map.png")
page := pdfjet.NewPage(pdf, letter.Portrait)
// Columns x coordinates
x1 := float32(75.0)
y1 := float32(75.0)
x2 := float32(325.0)
w2 := float32(200.0) // Width of the second column:
// Draw the first image
image1.SetLocation(x1, y1)
image1.ScaleBy(0.75)
image1.DrawOn(page)
textBlock := pdfjet.NewTextBox(f1)
textBlock.SetText("Geometry arose independently in a number of early cultures as a practical way for dealing with lengths, areas, and volumes.")
textBlock.SetLocation(x2, y1)
textBlock.SetWidth(w2)
textBlock.SetBorders(true)
// textBlock.SetTextAlignment(align.Right)
// textBlock.SetTextAlignment(align.Center)
xy := textBlock.DrawOn(page)
// Draw the second image
image2.SetLocation(x1, xy[1]+10.0)
image2.ScaleBy(1.0 / 3.0)
image2.DrawOn(page)
textBlock = pdfjet.NewTextBox(f1)
textBlock.SetText(contents.OfTextFile("data/latin.txt"))
textBlock.SetLocation(x2, xy[1]+10.0)
textBlock.SetWidth(w2)
textBlock.SetBorders(true)
textBlock.DrawOn(page)
textBlock = pdfjet.NewTextBox(f1)
textBlock.SetFallbackFont(f2)
textBlock.SetText(contents.OfTextFile("data/chinese.txt"))
textBlock.SetLocation(x1, 600.0)
textBlock.SetWidth(350.0)
textBlock.SetBorders(true)
textBlock.DrawOn(page)
pdf.Complete()
}
func main() {
start := time.Now()
Example19()
pdfjet.PrintDuration("Example_19", time.Since(start))
}