-
Notifications
You must be signed in to change notification settings - Fork 4
/
document_test.go
89 lines (81 loc) · 1.96 KB
/
document_test.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
85
86
87
88
89
package ofd
import (
"encoding/xml"
"os"
"path/filepath"
"testing"
)
const document_content = `
<?xml version="1.0" encoding="UTF-8"?>
<ofd:Document
xmlns:ofd="http://www.ofdspec.org/2016">
<ofd:CommonData>
<ofd:MaxUnitID>66</ofd:MaxUnitID>
<ofd:PageArea>
<ofd:PhysicalBox>0 0 210 297</ofd:PhysicalBox>
</ofd:PageArea>
<ofd:PublicRes>PublicRes_0.xml</ofd:PublicRes>
<ofd:DocumentRes>DocumentRes_0.xml</ofd:DocumentRes>
<ofd:TemplatePage ID="4" BaseLoc="Temps/Temp_0/Content.xml"/>
</ofd:CommonData>
<ofd:Pages>
<ofd:Page ID="6" BaseLoc="Pages/Page_0/Content.xml"/>
</ofd:Pages>
<ofd:Attachments>Attachs/Attachments.xml</ofd:Attachments>
<ofd:CustomTags>Tags/CustomTags.xml</ofd:CustomTags>
</ofd:Document>
`
func TestDocumentXml(t *testing.T) {
var doc Document
if err := xml.Unmarshal([]byte(document_content), &doc); err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", doc)
}
}
func TestDocument(t *testing.T) {
pwd, _ := os.Getwd()
file := filepath.Join(pwd, "samples", "DZHD_1605281110201000001_202205250016050102202100000069141950_20220525_000413.ofd")
ofdReader, err := NewOFDReader(file)
if err != nil {
t.Logf("%s", err)
}
defer ofdReader.Close()
ofd, err := ofdReader.OFD()
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", ofd)
}
index_0 := ofd.DocBody[0].DocInfo.DocID.Text
doc, err := ofdReader.GetDocumentById(index_0)
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", doc)
}
commonData, err := doc.GetCommonData()
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", commonData)
}
pages, err := doc.GetPages()
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", pages)
}
attachments, err := doc.GetAttachments()
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", attachments)
}
ct, err := doc.GetCustomTags()
if err != nil {
t.Logf("%v", err)
} else {
t.Logf("%v", ct)
}
}