PDFDestinationNamed.java
6.58 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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.cos.CosScalar
* com.adobe.internal.pdftoolkit.core.cos.CosString
* 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
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.interactive.navigation;
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.cos.CosScalar;
import com.adobe.internal.pdftoolkit.core.cos.CosString;
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.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCatalog;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFNameDictionary;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.PDFDestination;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.PDFDestinationExplicit;
import com.adobe.internal.pdftoolkit.pdf.interactive.navigation.PDFNamedDestinations;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPage;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPageFit;
public class PDFDestinationNamed
extends PDFDestination {
private PDFDestinationNamed(CosObject name) throws PDFInvalidDocumentException {
super(name);
if (name.getType() != 4 && name.getType() != 3) {
throw new PDFInvalidDocumentException("Cannot create named destination with non-string name");
}
}
public static PDFDestinationNamed getInstance(CosScalar cosObject) throws PDFInvalidDocumentException {
if (PDFCosObject.checkNullCosObject((CosObject)cosObject) == null) {
return null;
}
PDFDestinationNamed pdfObject = PDFCosObject.getCachedInstance((CosObject)cosObject, PDFDestinationNamed.class);
if (pdfObject == null) {
pdfObject = new PDFDestinationNamed((CosObject)cosObject);
}
return pdfObject;
}
public static PDFDestinationNamed newInstance(PDFDocument pdfDocument, ASString key, PDFDestinationExplicit dest) throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFNamedDestinations destTree = pdfDocument.requireCatalog().procureNameDictionary().procureNamedDestinations();
destTree.addEntry(key, dest);
CosString destName = PDFCosObject.newCosString(pdfDocument, key.getBytes());
return new PDFDestinationNamed((CosObject)destName);
}
public PDFPage getPage() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFDestinationExplicit explicitDest = this.retrieveExplicitDestination();
return explicitDest != null ? explicitDest.getPage() : null;
}
public PDFPageFit getPageFit() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFDestinationExplicit explicitDest = this.retrieveExplicitDestination();
return explicitDest != null ? explicitDest.getPageFit() : null;
}
public Number[] getCoordinates() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.retrieveExplicitDestination().getCoordinates();
}
public ASString getName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosName = this.getCosObject();
if (cosName.getType() == 3) {
return new ASString(cosName.nameValue().getBytes());
}
return new ASString((byte[])cosName.getValue());
}
public PDFDestinationExplicit getExplicitDestination() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.retrieveExplicitDestination();
}
private PDFDestinationExplicit retrieveExplicitDestination() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject name = this.getCosObject();
if (name.getType() == 3) {
return (PDFDestinationExplicit)this.get(((CosName)name).nameValue());
}
if (name.getType() == 4) {
PDFNameDictionary nameDict = this.getPDFDocument().requireCatalog().getNameDictionary();
if (nameDict == null) {
return null;
}
PDFNamedDestinations namedDests = nameDict.getNamedDestinations();
if (namedDests != null) {
return (PDFDestinationExplicit)namedDests.getEntry(((CosString)name).stringValue());
}
}
return null;
}
public PDFDestination get(ASName name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosDest = this.getPDFDocument().requireCatalog().getDictionaryCosObjectValue(ASName.k_Dests);
if (PDFCosObject.checkNullCosObject(cosDest) == null) {
return null;
}
if (cosDest instanceof CosDictionary) {
return PDFDestination.getInstance(((CosDictionary)cosDest).get(ASName.k_D));
}
return PDFDestination.getInstance(cosDest);
}
public boolean delete(ASName name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject cosDests = this.getPDFDocument().requireCatalog().getDictionaryCosObjectValue(ASName.k_Dests);
if (cosDests == null) {
return false;
}
CosObject cosDest = ((CosDictionary)cosDests).get(name);
if (cosDest == null) {
return false;
}
if (cosDest instanceof CosDictionary) {
((CosDictionary)cosDest).remove(ASName.k_D);
} else {
((CosDictionary)cosDests).remove(name);
}
return true;
}
}