-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdfcatalog.go
58 lines (46 loc) · 1.54 KB
/
pdfcatalog.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
package sign
import (
"strconv"
)
func (context *SignContext) createCatalog() (catalog string, err error) {
catalog = strconv.Itoa(int(context.CatalogData.ObjectId)) + " 0 obj\n"
catalog += "<< /Type /Catalog"
catalog += " /Version /" + context.PDFReader.PDFVersion
root := context.PDFReader.Trailer().Key("Root")
root_keys := root.Keys()
found_pages := false
for _, key := range root_keys {
if key == "Pages" {
found_pages = true
break
}
}
rootPtr := root.GetPtr()
context.CatalogData.RootString = strconv.Itoa(int(rootPtr.GetID())) + " " + strconv.Itoa(int(rootPtr.GetGen())) + " R"
if found_pages {
pages := root.Key("Pages").GetPtr()
catalog += " /Pages " + strconv.Itoa(int(pages.GetID())) + " " + strconv.Itoa(int(pages.GetGen())) + " R"
}
catalog += " /AcroForm <<"
catalog += " /Fields [" + strconv.Itoa(int(context.VisualSignData.ObjectId)) + " 0 R]"
switch context.SignData.Signature.CertType {
case CertificationSignature, UsageRightsSignature:
catalog += " /NeedAppearances false"
}
switch context.SignData.Signature.CertType {
case CertificationSignature:
catalog += " /SigFlags 3"
case UsageRightsSignature:
catalog += " /SigFlags 1"
}
catalog += " >>"
switch context.SignData.Signature.CertType {
case CertificationSignature:
catalog += " /Perms << /DocMDP " + strconv.Itoa(int(context.SignData.ObjectId)) + " 0 R >>"
case UsageRightsSignature:
catalog += " /Perms << /UR3 " + strconv.Itoa(int(context.SignData.ObjectId)) + " 0 R >>"
}
catalog += " >>"
catalog += "\nendobj\n"
return catalog, nil
}