/
informationdictionary.go
200 lines (176 loc) · 4.63 KB
/
informationdictionary.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
package types
import "errors"
// PDF Reference 1.4, Table 9.2 Entries in the document information dictionary
type InformationDictionary struct {
// (Optional; PDF 1.1) The document’s title.
Title String
// (Optional) The name of the person who created the document.
Author String
// (Optional; PDF 1.1) The subject of the document.
Subject String
// (Optional; PDF 1.1) Keywords associated with the document.
Keywords String
// (Optional) If the document was converted to PDF from another format, the
// name of the application (for example, Adobe FrameMaker®) that created the
// original document from which it was converted.
Creator String
// (Optional) If the document was converted to PDF from another format, the
// name of the application (for example, Acrobat Distiller) that converted it to
// PDF.
Producer String
// (Optional) The date and time the document was created, in human-readable
// form (see Section 3.8.2, “Dates”).
CreationDate Date
// (Optional; PDF 1.1) The date and time the document was most recently
// modified, in human-readable form (see Section 3.8.2, “Dates”).
ModDate Date
// (Optional; PDF 1.3) A name object indicating whether the document has
// been modified to include trapping information (see Section 9.10.5, “Trap-
// ping Support”):
Trapped Name
}
func (q InformationDictionary) ToRawBytes() []byte {
d := Dictionary{}
if q.Title != "" {
d["Title"] = q.Title
}
if q.Author != "" {
d["Author"] = q.Author
}
if q.Subject != "" {
d["Subject"] = q.Subject
}
if q.Keywords != "" {
d["Keywords"] = q.Keywords
}
if q.Creator != "" {
d["Creator"] = q.Creator
}
if q.Producer != "" {
d["Producer"] = q.Producer
}
if !q.CreationDate.IsZero() {
d["CreationDate"] = q.CreationDate
}
if !q.ModDate.IsZero() {
d["ModDate"] = q.ModDate
}
if q.Trapped != "" {
d["Trapped"] = q.Trapped
}
return d.ToRawBytes()
}
func (q *InformationDictionary) Read(dict Dictionary, file Resolver) error {
v, ok := dict.GetValue("Title", file)
if ok {
q.Title, ok = v.(String)
if !ok {
return errors.New("information dictionary field Title invalid")
}
}
v, ok = dict.GetValue("Author", file)
if ok {
q.Author, ok = v.(String)
if !ok {
return errors.New("information dictionary field Author invalid")
}
}
v, ok = dict.GetValue("Subject", file)
if ok {
q.Subject, ok = v.(String)
if !ok {
return errors.New("information dictionary field Subject invalid")
}
}
v, ok = dict.GetValue("Keywords", file)
if ok {
q.Keywords, ok = v.(String)
if !ok {
return errors.New("information dictionary field Keywords invalid")
}
}
v, ok = dict.GetValue("Creator", file)
if ok {
q.Creator, ok = v.(String)
if !ok {
return errors.New("information dictionary field Creator invalid")
}
}
v, ok = dict.GetValue("Producer", file)
if ok {
q.Producer, ok = v.(String)
if !ok {
return errors.New("information dictionary field Producer invalid")
}
}
v, ok = dict.GetValue("CreationDate", file)
if ok {
q.CreationDate, ok = v.(Date)
if !ok {
return errors.New("information dictionary field CreationDate invalid")
}
}
v, ok = dict.GetValue("ModDate", file)
if ok {
q.ModDate, ok = v.(Date)
if !ok {
return errors.New("information dictionary field ModDate invalid")
}
}
v, ok = dict.GetValue("Trapped", file)
if ok {
q.Trapped, ok = v.(Name)
if !ok {
return errors.New("information dictionary field Trapped invalid")
}
}
// return without error
return nil
}
func (q InformationDictionary) Copy(copyRef func(reference Reference) Reference) Object {
return InformationDictionary{
Title: q.Title.Copy(copyRef).(String),
Author: q.Author.Copy(copyRef).(String),
Subject: q.Subject.Copy(copyRef).(String),
Keywords: q.Keywords.Copy(copyRef).(String),
Creator: q.Creator.Copy(copyRef).(String),
Producer: q.Producer.Copy(copyRef).(String),
CreationDate: q.CreationDate.Copy(copyRef).(Date),
ModDate: q.ModDate.Copy(copyRef).(Date),
Trapped: q.Trapped.Copy(copyRef).(Name),
}
}
func (q InformationDictionary) Equal(obj Object) bool {
a, ok := obj.(InformationDictionary)
if !ok {
return false
}
if !Equal(q.Title, a.Title) {
return false
}
if !Equal(q.Author, a.Author) {
return false
}
if !Equal(q.Subject, a.Subject) {
return false
}
if !Equal(q.Keywords, a.Keywords) {
return false
}
if !Equal(q.Creator, a.Creator) {
return false
}
if !Equal(q.Producer, a.Producer) {
return false
}
if !Equal(q.CreationDate, a.CreationDate) {
return false
}
if !Equal(q.ModDate, a.ModDate) {
return false
}
if !Equal(q.Trapped, a.Trapped) {
return false
}
return true
}