-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathpdf_test.go
More file actions
151 lines (129 loc) · 2.98 KB
/
Copy pathpdf_test.go
File metadata and controls
151 lines (129 loc) · 2.98 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package pdft
import (
"testing"
gopdf "github.com/signintech/pdft/minigopdf"
)
func TestPDF(t *testing.T) {
pdf(t, "pdf_from_gopdf.pdf")
//pdf(t, "pdf_from_docx.pdf")
pdf(t, "pdf_from_docx_with_f.pdf")
//pdf(t, "pdf_from_iia.pdf")
//pdf(t, "pdf_from_delphi.pdf")
//pdf(t, "pdf_from_word2010.pdf")
//pdf(t, "pdf_from_word2010_b.pdf")
//pdf(t, "pdf_from_chrome_50_win10.pdf")
//pdf(t, "pdf_from_chrome_50_linux64.pdf")
pdf(t, "pdf_from_word2013.pdf")
//pdf(t, "pdf_from_word2013_b.pdf")
//pdf(t, "pdf_from_rdlc.pdf")
}
func pdf(t *testing.T, filename string) {
var ipdf PDFt
//err := ipdf.Open("test/pdf/pdf_from_docx_with_f.pdf")
err := ipdf.Open("test/pdf/" + filename)
//err := ipdf.Open("test/pdf/pdf_from_docx.pdf")
if err != nil {
t.Error(err)
return
}
err = ipdf.AddFont("arial", "test/ttf/angsa.ttf")
if err != nil {
t.Error(err)
return
}
err = ipdf.SetFont("arial", "", 14)
if err != nil {
t.Error(err)
return
}
err = ipdf.Insert("ที่ กั้น", 1, 10, 10, 100, 100, gopdf.Center|gopdf.Bottom, nil)
if err != nil {
t.Error(err)
return
}
ipdf.SetProtection(
gopdf.PermissionsPrint|gopdf.PermissionsCopy|gopdf.PermissionsModify,
[]byte("1234"),
[]byte("5555"),
)
err = ipdf.Save("test/out/" + filename)
if err != nil {
t.Error(err)
return
}
}
func TestMeasureTextWidth(t *testing.T) {
filename := "pdf_from_docx_with_f.pdf"
var ipdf PDFt
//err := ipdf.Open("test/pdf/pdf_from_docx_with_f.pdf")
err := ipdf.Open("test/pdf/" + filename)
//err := ipdf.Open("test/pdf/pdf_from_docx.pdf")
if err != nil {
t.Error(err)
return
}
err = ipdf.AddFont("arial", "test/ttf/angsa.ttf")
if err != nil {
t.Error(err)
return
}
err = ipdf.SetFont("arial", "", 14)
if err != nil {
t.Error(err)
return
}
width1, err := ipdf.MeasureTextWidth("การปั้นโต้ง")
if err != nil {
t.Error(err)
return
}
width2, err := ipdf.MeasureTextWidth("การปั้นโต้งการปั้นโต้ง")
if err != nil {
t.Error(err)
return
}
err = ipdf.SetFont("arial", "", 15)
if err != nil {
t.Error(err)
return
}
width3, err := ipdf.MeasureTextWidth("การปั้นโต้ง")
if err != nil {
t.Error(err)
return
}
if width1*2 != width2 {
t.Error("width1 * 2 != width2")
}
if width1 == width3 {
t.Error("width1 == width3")
}
//gitfmt.Printf("%f %f %f\n", width1, width2, width3)
}
/*
func TestSlice(t *testing.T) {
src := []byte("ABCDEFGHIJ")
dest := src[9:10]
fmt.Printf("src=%d dest=%d\n", cap(src), cap(dest))
dest = append(dest, []byte("1234567890123456789012345678901")...)
fmt.Println(string(src))
}*/
func TestRemoveOtherPages(t *testing.T) {
filename := "pdf_from_docx_with_f.pdf"
var ipdf PDFt
err := ipdf.Open("test/pdf/" + filename)
if err != nil {
t.Error(err)
return
}
err = ipdf.RemoveOtherPages(1)
if err != nil {
t.Error(err)
return
}
err = ipdf.Save("test/out/RemoveOtherPages_" + filename)
if err != nil {
t.Error(err)
return
}
}