@@ -61,7 +61,7 @@ public class PdfCatalog extends PdfObjectWrapper<PdfDictionary> {
61
61
62
62
private static final long serialVersionUID = -1354567597112193418L ;
63
63
64
- final PdfPagesTree pageTree ;
64
+ final private PdfPagesTree pageTree ;
65
65
protected Map <PdfName , PdfNameTree > nameTrees = new HashMap <>();
66
66
protected PdfNumTree pageLabels ;
67
67
protected PdfOCProperties ocProperties ;
@@ -88,42 +88,6 @@ protected PdfCatalog(PdfDocument pdfDocument) {
88
88
this (new PdfDictionary ().makeIndirect (pdfDocument ));
89
89
}
90
90
91
- public void addPage (PdfPage page ) {
92
- if (page .isFlushed ())
93
- throw new PdfException (PdfException .FlushedPageCannotBeAddedOrInserted , page );
94
- if (page .getDocument () != null && page .getDocument () != getDocument ())
95
- throw new PdfException (PdfException .Page1CannotBeAddedToDocument2BecauseItBelongsToDocument3 ).setMessageParams (page , getDocument (), page .getDocument ());
96
- pageTree .addPage (page );
97
- }
98
-
99
- public void addPage (int index , PdfPage page ) {
100
- if (page .isFlushed ())
101
- throw new PdfException (PdfException .FlushedPageCannotBeAddedOrInserted , page );
102
- if (page .getDocument () != null && page .getDocument () != getDocument ())
103
- throw new PdfException (PdfException .Page1CannotBeAddedToDocument2BecauseItBelongsToDocument3 ).setMessageParams (page , getDocument (), page .getDocument ());
104
- pageTree .addPage (index , page );
105
- }
106
-
107
- public PdfPage getPage (int pageNum ) {
108
- return pageTree .getPage (pageNum );
109
- }
110
-
111
- public PdfPage getPage (PdfDictionary pageDictionary ) {
112
- return pageTree .getPage (pageDictionary );
113
- }
114
-
115
- public int getNumberOfPages () {
116
- return pageTree .getNumberOfPages ();
117
- }
118
-
119
- public int getPageNumber (PdfPage page ) {
120
- return pageTree .getPageNumber (page );
121
- }
122
-
123
- public int getPageNumber (PdfDictionary pageDictionary ) {
124
- return pageTree .getPageNumber (pageDictionary );
125
- }
126
-
127
91
/**
128
92
* Use this method to get the <B>Optional Content Properties Dictionary</B>.
129
93
* Note that if you call this method, then the PdfDictionary with OCProperties will be
@@ -188,25 +152,28 @@ public PdfCatalog setAdditionalAction(PdfName key, PdfAction action) {
188
152
/**
189
153
* This flag determines if Outline tree of the document has been built via calling getOutlines method. If this flag is false all outline operations will be ignored
190
154
*
191
- * @return
155
+ * @return state of outline mode.
192
156
*/
193
157
public boolean isOutlineMode () {
194
158
return outlineMode ;
195
159
}
196
160
197
161
/**
198
- * This method sets a page mode of the document
162
+ * This method sets a page mode of the document.
163
+ * </p>
164
+ * Valid values are: {@code PdfName.UseNone}, {@code PdfName.UseOutlines}, {@code PdfName.UseThumbs},
165
+ * {@code PdfName.FullScreen}, {@code PdfName.UseOC}, {@code PdfName.UseAttachments}.
199
166
*
200
- * @param pageMode
201
- * @return
167
+ * @param pageMode page mode.
168
+ * @return current instance of PdfCatalog
202
169
*/
203
170
public PdfCatalog setPageMode (PdfName pageMode ) {
204
- if (! pageMode .equals (PdfName .UseNone ) && ! pageMode .equals (PdfName .UseOutlines ) &&
205
- ! pageMode .equals (PdfName .UseThumbs ) && ! pageMode .equals (PdfName .FullScreen ) &&
206
- ! pageMode .equals (PdfName .UseOC ) && ! pageMode .equals (PdfName .UseAttachments )) {
207
- return this ;
171
+ if (pageMode .equals (PdfName .UseNone ) || pageMode .equals (PdfName .UseOutlines ) ||
172
+ pageMode .equals (PdfName .UseThumbs ) || pageMode .equals (PdfName .FullScreen ) ||
173
+ pageMode .equals (PdfName .UseOC ) || pageMode .equals (PdfName .UseAttachments )) {
174
+ return put ( PdfName . PageMode , pageMode ) ;
208
175
}
209
- return put ( PdfName . PageMode , pageMode ) ;
176
+ return this ;
210
177
}
211
178
212
179
public PdfName getPageMode () {
@@ -219,12 +186,12 @@ public PdfName getPageMode() {
219
186
* @return
220
187
*/
221
188
public PdfCatalog setPageLayout (PdfName pageLayout ) {
222
- if (! pageLayout .equals (PdfName .SinglePage ) && ! pageLayout .equals (PdfName .OneColumn ) &&
223
- ! pageLayout .equals (PdfName .TwoColumnLeft ) && ! pageLayout .equals (PdfName .TwoColumnRight ) &&
224
- ! pageLayout .equals (PdfName .TwoPageLeft ) && ! pageLayout .equals (PdfName .TwoPageRight )) {
225
- return this ;
189
+ if (pageLayout .equals (PdfName .SinglePage ) || pageLayout .equals (PdfName .OneColumn ) ||
190
+ pageLayout .equals (PdfName .TwoColumnLeft ) || pageLayout .equals (PdfName .TwoColumnRight ) ||
191
+ pageLayout .equals (PdfName .TwoPageLeft ) || pageLayout .equals (PdfName .TwoPageRight )) {
192
+ return put ( PdfName . PageLayout , pageLayout ) ;
226
193
}
227
- return put ( PdfName . PageLayout , pageLayout ) ;
194
+ return this ;
228
195
}
229
196
230
197
public PdfName getPageLayout (){
@@ -253,7 +220,7 @@ public PdfViewerPreferences getViewerPreferences() {
253
220
/**
254
221
* This method gets Names tree from the catalog.
255
222
* @param treeType type of the tree (Dests, AP, EmbeddedFiles etc).
256
- * @return
223
+ * @return returns {@link PdfNameTree}
257
224
*/
258
225
public PdfNameTree getNameTree (PdfName treeType ) {
259
226
PdfNameTree tree = nameTrees .get (treeType );
@@ -267,7 +234,7 @@ public PdfNameTree getNameTree(PdfName treeType) {
267
234
268
235
/**
269
236
* This method returns the NumberTree of Page Labels
270
- * @return
237
+ * @return returns {@link PdfNumTree}
271
238
*/
272
239
public PdfNumTree getPageLabelsTree (boolean createIfNotExists ) {
273
240
if (pageLabels == null && (getPdfObject ().containsKey (PdfName .PageLabels ) || createIfNotExists )) {
@@ -343,9 +310,10 @@ protected boolean isOCPropertiesMayHaveChanged() {
343
310
return ocProperties != null ;
344
311
}
345
312
346
- PdfPage removePage ( int pageNum ) {
347
- return pageTree . removePage ( pageNum ) ;
313
+ PdfPagesTree getPageTree ( ) {
314
+ return pageTree ;
348
315
}
316
+
349
317
/**
350
318
* this method return map containing all pages of the document with associated outlines.
351
319
*
@@ -476,7 +444,7 @@ PdfDestination copyDestination(PdfObject dest, Map<PdfPage, PdfPage> page2page,
476
444
if (oldPage .getPdfObject () == pageObject ) {
477
445
array .set (0 , page2page .get (oldPage ).getPdfObject ());
478
446
d = new PdfStringDestination (name );
479
- toDocument .addNameDestination (name ,array );
447
+ toDocument .addNamedDestination (name ,array );
480
448
}
481
449
}
482
450
}
0 commit comments