PDFViewerPreferences.java
16.4 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosName
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.interactive;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosName;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFASNameInterface;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.interactive.PDFJSDebuggerConsoleState;
import com.adobe.internal.pdftoolkit.pdf.interactive.PDFPredominantReadingOrder;
import com.adobe.internal.pdftoolkit.pdf.interactive.PDFPrintScaling;
import com.adobe.internal.pdftoolkit.pdf.interactive.PDFPrintingPaperHandling;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPageBoundary;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPageMode;
public class PDFViewerPreferences
extends PDFCosDictionary {
public static final ASName k_PrintScaling = ASName.create((String)"PrintScaling");
protected static final ASName k_Duplex = ASName.create((String)"Duplex");
protected static final ASName k_PickTrayByPDFSize = ASName.create((String)"PickTrayByPDFSize");
protected static final ASName k_PrintPageRange = ASName.create((String)"PrintPageRange");
protected static final ASName k_NumCopies = ASName.create((String)"NumCopies");
protected static final ASName k_Rights = ASName.create((String)"Rights");
protected static final ASName k_Enforce = ASName.create((String)"Enforce");
protected static final ASName k_ADBE_JSDebugger = ASName.create((String)"ADBE_JSDebugger");
protected static final ASName k_ADBE_JSConsole = ASName.create((String)"ADBE_JSConsole");
public static final ASName k_Enable = ASName.create((String)"Enable");
public static final ASName k_Disable = ASName.create((String)"Disable");
public static final ASName k_Delegate = ASName.create((String)"Delegate");
private PDFViewerPreferences(CosObject cosObject) throws PDFInvalidDocumentException {
super(cosObject);
}
public static PDFViewerPreferences getInstance(CosObject cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFViewerPreferences pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFViewerPreferences.class);
if (pdfObject == null) {
pdfObject = new PDFViewerPreferences(cosObject);
}
return pdfObject;
}
public static PDFViewerPreferences newInstance(PDFDocument pdfDocument) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary cosObject = PDFCosObject.newCosDictionary(pdfDocument);
return new PDFViewerPreferences((CosObject)cosObject);
}
public void setHideToolbar(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_HideToolbar, on);
}
public boolean getHideToolbar() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_HideToolbar)) {
return this.getDictionaryBooleanValue(ASName.k_HideToolbar);
}
return false;
}
public void setHideMenubar(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_HideMenubar, on);
}
public boolean getHideMenubar() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_HideMenubar)) {
return this.getDictionaryBooleanValue(ASName.k_HideMenubar);
}
return false;
}
public void setHideWindowUI(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_HideWindowUI, on);
}
public boolean getHideWindowUI() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_HideWindowUI)) {
return this.getDictionaryBooleanValue(ASName.k_HideWindowUI);
}
return false;
}
public void setFitWindow(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_FitWindow, on);
}
public boolean getFitWindow() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_FitWindow)) {
return this.getDictionaryBooleanValue(ASName.k_FitWindow);
}
return false;
}
public void setCenterWindow(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_CenterWindow, on);
}
public boolean getCenterWindow() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_CenterWindow)) {
return this.getDictionaryBooleanValue(ASName.k_CenterWindow);
}
return false;
}
public void setDisplayDocTitle(boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_DisplayDocTitle, on);
}
public boolean getDisplayDocTitle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(ASName.k_DisplayDocTitle)) {
return this.getDictionaryBooleanValue(ASName.k_DisplayDocTitle);
}
return false;
}
public void setPageMode(PDFPageMode pageMode) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_NonFullScreenPageMode, pageMode);
}
public PDFPageMode getPageMode() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPageMode mode = PDFPageMode.getInstance(this.getDictionaryNameValue(ASName.k_NonFullScreenPageMode));
if (mode == null) {
return PDFPageMode.PagesOnly;
}
return mode;
}
public void setDirection(PDFPredominantReadingOrder direction) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Direction, direction);
}
public PDFPredominantReadingOrder getDirection() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPredominantReadingOrder order = PDFPredominantReadingOrder.getInstance(this.getDictionaryNameValue(ASName.k_Direction));
if (order == null) {
return PDFPredominantReadingOrder.LeftToRight;
}
return order;
}
public void setViewArea(PDFPageBoundary viewArea) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_ViewArea, viewArea);
}
public PDFPageBoundary getViewArea() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPageBoundary boundary = PDFPageBoundary.getInstance(this.getDictionaryNameValue(ASName.k_ViewArea));
if (boundary == null) {
return PDFPageBoundary.CropBox;
}
return boundary;
}
public void setViewClip(PDFPageBoundary viewClip) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_ViewClip, viewClip);
}
public PDFPageBoundary getViewClip() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPageBoundary boundary = PDFPageBoundary.getInstance(this.getDictionaryNameValue(ASName.k_ViewClip));
if (boundary == null) {
return PDFPageBoundary.CropBox;
}
return boundary;
}
public void setPrintArea(PDFPageBoundary printArea) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_PrintArea, printArea);
}
public PDFPageBoundary getPrintArea() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPageBoundary boundary = PDFPageBoundary.getInstance(this.getDictionaryNameValue(ASName.k_PrintArea));
if (boundary == null) {
return PDFPageBoundary.CropBox;
}
return boundary;
}
public void setPrintClip(PDFPageBoundary printClip) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_PrintClip, printClip);
}
public PDFPageBoundary getPrintClip() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPageBoundary boundary = PDFPageBoundary.getInstance(this.getDictionaryNameValue(ASName.k_PrintClip));
if (boundary == null) {
return PDFPageBoundary.CropBox;
}
return boundary;
}
public void setPrintScaling(PDFPrintScaling printScaling) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(k_PrintScaling, printScaling);
}
public PDFPrintScaling getPrintScaling() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFPrintScaling scaling = PDFPrintScaling.getInstance(this.getDictionaryNameValue(k_PrintScaling));
if (scaling == null) {
return PDFPrintScaling.AppDefault;
}
return scaling;
}
public void setEnforce(ASName[] entries) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (entries == null || entries.length == 0) {
if (this.dictionaryContains(k_Enforce)) {
this.removeValue(k_Enforce);
}
return;
}
CosArray cosEntries = PDFCosObject.newCosArray(this.getPDFDocument());
for (int i = 0; i < entries.length; ++i) {
ASName printScaling;
if (entries[i] != k_PrintScaling || !this.dictionaryContains(k_PrintScaling) || (printScaling = this.getDictionaryNameValue(k_PrintScaling)) == PDFPrintScaling.AppDefault.getName()) continue;
CosName cosName = PDFCosObject.newCosName(this.getPDFDocument(), k_PrintScaling);
cosEntries.add((CosObject)cosName);
}
this.setDictionaryArrayValue(k_Enforce, cosEntries);
}
public ASName[] getEnforce() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosArray cosEnforce = this.getDictionaryArrayValue(k_Enforce);
ASName[] namesEnforced = null;
if (cosEnforce != null && cosEnforce.size() > 0) {
namesEnforced = new ASName[cosEnforce.size()];
for (int i = 0; i < cosEnforce.size(); ++i) {
namesEnforced[i] = cosEnforce.getName(i);
}
}
return namesEnforced;
}
public void setDuplex(PDFPrintingPaperHandling paperHandling) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(k_Duplex, paperHandling);
}
public PDFPrintingPaperHandling getDuplex() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFPrintingPaperHandling.getInstance(this.getDictionaryNameValue(k_Duplex));
}
public void setPickTrayByPDFSize(Boolean on) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(k_PickTrayByPDFSize, on);
}
public boolean getPickTrayByPDFSize() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_PickTrayByPDFSize)) {
return this.getDictionaryBooleanValue(k_PickTrayByPDFSize);
}
return false;
}
public void setPrintPageRange(int[] pages) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (pages != null) {
if (pages.length % 2 != 0) {
throw new PDFInvalidParameterException("Array of page numbers must contain an even number");
}
for (int i = 0; i < pages.length; ++i) {
if (pages[i] >= 0) continue;
throw new PDFInvalidParameterException("A negative page number in the array.");
}
}
this.setDictionaryArrayValue(k_PrintPageRange, pages);
}
public int[] getPrintPageRange() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_PrintPageRange)) {
CosArray pages = this.getDictionaryArrayValue(k_PrintPageRange);
return pages.getArrayInt();
}
return null;
}
public void setNumCopies(Long copies) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
if (copies == null) {
this.removeValue(k_NumCopies);
} else {
this.setDictionaryIntValue(k_NumCopies, copies);
}
}
public int getNumCopies() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_NumCopies)) {
return this.getDictionaryIntValue(k_NumCopies);
}
return 1;
}
public PDFJSDebuggerConsoleState getPDFJSDebuggerState() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_ADBE_JSDebugger)) {
ASName stateName = this.getDictionaryNameValue(k_ADBE_JSDebugger);
PDFJSDebuggerConsoleState state = PDFJSDebuggerConsoleState.getInstance(stateName);
if (state == null) {
throw new PDFInvalidDocumentException("Invalid Value of JS Debugger present in Viewer Preferences Dictionary, invalid Value :" + (Object)stateName);
}
return state;
}
return PDFJSDebuggerConsoleState.Delegate;
}
public void setPDFJSDebuggerState(PDFJSDebuggerConsoleState state) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName stateName = state == null ? null : state.getName();
this.setDictionaryNameValue(k_ADBE_JSDebugger, stateName);
}
public PDFJSDebuggerConsoleState getPDFJSConsoleState() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.dictionaryContains(k_ADBE_JSConsole)) {
ASName stateName = this.getDictionaryNameValue(k_ADBE_JSConsole);
PDFJSDebuggerConsoleState state = PDFJSDebuggerConsoleState.getInstance(stateName);
if (state == null) {
throw new PDFInvalidDocumentException("Invalid Value of JS Console present in Viewer Preferences Dictionary, invalid Value :" + (Object)stateName);
}
return state;
}
return PDFJSDebuggerConsoleState.Delegate;
}
public void setPDFJSConsoleState(PDFJSDebuggerConsoleState state) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName stateName = state == null ? null : state.getName();
this.setDictionaryNameValue(k_ADBE_JSConsole, stateName);
}
public CosDictionary getRights() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryDictionaryValue(k_Rights);
}
public void removeRights() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.removeValue(k_Rights);
}
}