-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacroform_obj.go
More file actions
53 lines (42 loc) · 1.11 KB
/
acroform_obj.go
File metadata and controls
53 lines (42 loc) · 1.11 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
package gopdf
import (
"fmt"
"io"
)
// acroFormObj is the PDF AcroForm dictionary object.
type acroFormObj struct {
fieldObjIDs []int // 1-based object IDs of form field objects
fontRefs []acroFormFont // fonts used in form fields
needAppearances bool
}
type acroFormFont struct {
name string // e.g. "F1"
objID int // 1-based
}
func (a acroFormObj) init(fn func() *GoPdf) {}
func (a acroFormObj) getType() string {
return "AcroForm"
}
func (a acroFormObj) write(w io.Writer, objID int) error {
io.WriteString(w, "<<\n")
// Fields array
io.WriteString(w, "/Fields [")
for _, id := range a.fieldObjIDs {
fmt.Fprintf(w, "%d 0 R ", id)
}
io.WriteString(w, "]\n")
// NeedAppearances — tells viewers to generate appearances
io.WriteString(w, "/NeedAppearances true\n")
// Default resources with fonts
if len(a.fontRefs) > 0 {
io.WriteString(w, "/DR << /Font <<")
for _, f := range a.fontRefs {
fmt.Fprintf(w, " /%s %d 0 R", f.name, f.objID)
}
io.WriteString(w, " >> >>\n")
}
// Default appearance
io.WriteString(w, "/DA (/Helv 12 Tf 0 0 0 rg)\n")
io.WriteString(w, ">>\n")
return nil
}