-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes.go
209 lines (172 loc) · 4.37 KB
/
types.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package pdf_parser
import (
"errors"
"strings"
)
const BufferSize = 50
const BufferSize300 = 300
var (
fileIsNotPdfError = errors.New("file is not pdf")
cannotReadXrefOffset = errors.New("cannot read OriginalXrefOffset")
cannotParseXrefOffset = errors.New("cannot parse OriginalXrefOffset")
cannotParseXrefSection = errors.New("cannot parse XrefSection")
cannotFindObjectById = errors.New("cannot find object in Xref table")
cannotFindRootObject = errors.New("cannot find root object")
cannotFindInfoObject = errors.New("cannot find info object")
cannotParseTrailer = errors.New("cannot parse trailer section")
cannotParseObject = errors.New("cannot parse xref Object")
unsupportedParseContent = errors.New("unsupported stream decode content")
cannotFindStreamContent = errors.New("cannot find stream content")
invalidXrefTableStructure = errors.New("invalid Xref table structure")
invalidSearchIndex = errors.New("invalid search index")
)
type PdfInfo struct {
PdfVersion string
OriginalXrefOffset int64
OriginalTrailerSection TrailerSection
AdditionalTrailerSection []*TrailerSection
XrefTable []*XrefTable
Root RootObject
Info InfoObject
Metadata Metadata
PagesCount int
}
func (pdf *PdfInfo) GetTitle() string {
if pdf.Info.Title != "" {
return pdf.Info.Title
}
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Title
}
return ""
}
func (pdf *PdfInfo) GetAuthor() string {
if pdf.Info.Author != "" {
return pdf.Info.Author
}
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Creator
}
return ""
}
func (pdf *PdfInfo) GetCreator() string {
if pdf.Info.Creator != "" {
return pdf.Info.Creator
}
return ""
}
func (pdf *PdfInfo) GetISBN() string {
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Isbn
}
return ""
}
func (pdf *PdfInfo) GetPublishers() []string {
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Publishers
}
return []string{}
}
func (pdf *PdfInfo) GetLanguages() []string {
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Languages
}
return []string{}
}
func (pdf *PdfInfo) GetLanguage() string {
if pdf.Metadata.RdfMeta != nil {
return strings.Join(pdf.Metadata.RdfMeta.Languages, ",")
}
return ""
}
func (pdf *PdfInfo) GetDate() string {
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Date
}
return ""
}
func (pdf *PdfInfo) GetPublisherInfo() string {
if pdf.Metadata.RdfMeta != nil {
return strings.Join(pdf.Metadata.RdfMeta.Publishers, ",")
}
return ""
}
func (pdf *PdfInfo) GetDescription() string {
if pdf.Metadata.RdfMeta != nil {
return pdf.Metadata.RdfMeta.Description
}
return ""
}
func (pdf *PdfInfo) GetPagesCount() int {
return pdf.PagesCount
}
func (pdf *PdfInfo) GetCover(filepath string) bool {
//TODO finish this
isSuccess := false
return isSuccess
}
type TrailerSection struct {
IdRaw string
Info ObjectIdentifier
Root ObjectIdentifier
Size string
Prev int64
}
type ObjectIdentifier struct {
ObjectNumber int
GenerationNumber int
KeyWord string
}
type ObjectSubsectionElement struct {
Id int
ObjectNumber int
GenerationNumber int
KeyWord string
}
/*
Object subsection that contain list of objects for this object
*/
type ObjectSubsection struct {
Id int // objectId
ObjectsCount int
FirstSubsectionObjectId int
LastSubsectionObjectId int
Elements map[int]*ObjectSubsectionElement
}
type XrefTable struct {
Objects map[int]*ObjectSubsectionElement
ObjectSubsections map[int]*ObjectSubsection
SectionStart int64
}
type InfoObject struct {
Title string
Author string
Creator string
CreationDate string
Producer string
ModDate string
}
type RootObject struct {
Type string
Pages *ObjectIdentifier
Metadata *ObjectIdentifier
PageLabels *ObjectIdentifier
Lang string
}
type Metadata struct {
Type string
Subtype string
Length int64
DL int64
RawStreamData []byte
RdfMeta *MetaDataRdf
}
type MetaDataRdf struct {
Title string
Description string
Creator string
Date string
Isbn string
Publishers []string
Languages []string
}