forked from pdfcpu/pdfcpu
/
configuration.go
155 lines (121 loc) · 3.64 KB
/
configuration.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
/*
Copyright 2018 The pdfcpu Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package pdfcpu
const (
// ValidationStrict ensures 100% compliance with the spec (PDF 32000-1:2008).
ValidationStrict = 0
// ValidationRelaxed ensures PDF compliance based on frequently encountered validation errors.
ValidationRelaxed = 1
// StatsFileNameDefault is the standard stats filename.
StatsFileNameDefault = "stats.csv"
// PermissionsAll enables all user access permission bits.
PermissionsAll int16 = -1 // 0xFFFF
// PermissionsNone disables all user access permissions bits.
PermissionsNone int16 = -3901 // 0xF0C3
)
// CommandMode specifies the operation being executed.
type CommandMode int
// The available commands.
const (
VALIDATE CommandMode = iota
OPTIMIZE
SPLIT
MERGE
EXTRACTIMAGES
EXTRACTFONTS
EXTRACTPAGES
EXTRACTCONTENT
EXTRACTMETADATA
TRIM
ADDATTACHMENTS
REMOVEATTACHMENTS
EXTRACTATTACHMENTS
LISTATTACHMENTS
ADDPERMISSIONS
LISTPERMISSIONS
ENCRYPT
DECRYPT
CHANGEUPW
CHANGEOPW
STAMP
ADDWATERMARKS
IMPORTIMAGES
ROTATE
NUP
)
// Configuration of a Context.
type Configuration struct {
// Enables PDF V1.5 compatible processing of object streams, xref streams, hybrid PDF files.
Reader15 bool
// Enables decoding of all streams (fontfiles, images..) for logging purposes.
DecodeAllStreams bool
// Validate against ISO-32000: strict or relaxed
ValidationMode int
// End of line char sequence for writing.
Eol string
// Turns on object stream generation.
// A signal for compressing any new non-stream-object into an object stream.
// true enforces WriteXRefStream to true.
// false does not prevent xRefStream generation.
WriteObjectStream bool
// Switches between xRefSection (<=V1.4) and objectStream/xRefStream (>=V1.5) writing.
WriteXRefStream bool
// Turns on stats collection.
// TODO Decision - unused.
CollectStats bool
// A CSV-filename holding the statistics.
StatsFileName string
// Supplied user password
UserPW string
UserPWNew *string
// Supplied owner password
OwnerPW string
OwnerPWNew *string
// EncryptUsingAES ensures AES encryption.
// true: AES encryption
// false: RC4 encryption.
EncryptUsingAES bool
// EncryptUsing128BitKey ensures 128 bit key length.
// true: use 128 bit key
// false: use 40 bit key
EncryptUsing128BitKey bool
// Supplied user access permissions, see Table 22
UserAccessPermissions int16
// Command being executed.
Mode CommandMode
}
// NewDefaultConfiguration returns the default pdfcpu configuration.
func NewDefaultConfiguration() *Configuration {
return &Configuration{
Reader15: true,
DecodeAllStreams: false,
ValidationMode: ValidationRelaxed,
Eol: EolLF,
WriteObjectStream: true,
WriteXRefStream: true,
CollectStats: true,
EncryptUsingAES: true,
EncryptUsing128BitKey: true,
UserAccessPermissions: PermissionsNone,
}
}
// ValidationModeString returns a string rep for the validation mode in effect.
func (c *Configuration) ValidationModeString() string {
if c.ValidationMode == ValidationStrict {
return "strict"
}
if c.ValidationMode == ValidationRelaxed {
return "relaxed"
}
return ""
}