Skip to content

Commit 0cf5963

Browse files
committed
Merge branch 'develop' into layoutsharp2
Conflicts: layout/src/main/java/com/itextpdf/layout/ElementPropertyContainer.java layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java
2 parents a858b3e + 951d300 commit 0cf5963

File tree

24 files changed

+255
-280
lines changed

24 files changed

+255
-280
lines changed

forms/src/main/java/com/itextpdf/forms/PdfAcroForm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ private void defineWidgetPageAndAddToIt(PdfPage currentPage, PdfDictionary merge
885885
throw new PdfException(PdfException.PageWasAlreadyFlushedUseAddFieldAppearanceToPageMethodBeforePageFlushing);
886886
}
887887
PdfDocument doc = pageDic.getIndirectReference().getDocument();
888-
PdfPage widgetPage = doc.getCatalog().getPage(pageDic);
888+
PdfPage widgetPage = doc.getPage(pageDic);
889889
addWidgetAnnotationToPage(widgetPage, annot);
890890
} else {
891891
addWidgetAnnotationToPage(currentPage, annot);
@@ -1027,7 +1027,7 @@ private static PdfDictionary createAcroFormDictionaryByFields(PdfArray fields) {
10271027
private PdfPage getFieldPage(PdfDictionary annotDic) {
10281028
PdfDictionary pageDic = annotDic.getAsDictionary(PdfName.P);
10291029
if (pageDic != null) {
1030-
return document.getCatalog().getPage(pageDic);
1030+
return document.getPage(pageDic);
10311031
}
10321032
for (int i = 1; i <= document.getNumberOfPages(); i++) {
10331033
PdfPage page = document.getPage(i);

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfCatalog.java

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class PdfCatalog extends PdfObjectWrapper<PdfDictionary> {
6161

6262
private static final long serialVersionUID = -1354567597112193418L;
6363

64-
final PdfPagesTree pageTree;
64+
final private PdfPagesTree pageTree;
6565
protected Map<PdfName, PdfNameTree> nameTrees = new HashMap<>();
6666
protected PdfNumTree pageLabels;
6767
protected PdfOCProperties ocProperties;
@@ -88,42 +88,6 @@ protected PdfCatalog(PdfDocument pdfDocument) {
8888
this(new PdfDictionary().makeIndirect(pdfDocument));
8989
}
9090

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-
12791
/**
12892
* Use this method to get the <B>Optional Content Properties Dictionary</B>.
12993
* 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) {
188152
/**
189153
* 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
190154
*
191-
* @return
155+
* @return state of outline mode.
192156
*/
193157
public boolean isOutlineMode() {
194158
return outlineMode;
195159
}
196160

197161
/**
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}.
199166
*
200-
* @param pageMode
201-
* @return
167+
* @param pageMode page mode.
168+
* @return current instance of PdfCatalog
202169
*/
203170
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);
208175
}
209-
return put(PdfName.PageMode, pageMode);
176+
return this;
210177
}
211178

212179
public PdfName getPageMode() {
@@ -219,12 +186,12 @@ public PdfName getPageMode() {
219186
* @return
220187
*/
221188
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);
226193
}
227-
return put(PdfName.PageLayout, pageLayout);
194+
return this;
228195
}
229196

230197
public PdfName getPageLayout(){
@@ -253,7 +220,7 @@ public PdfViewerPreferences getViewerPreferences() {
253220
/**
254221
* This method gets Names tree from the catalog.
255222
* @param treeType type of the tree (Dests, AP, EmbeddedFiles etc).
256-
* @return
223+
* @return returns {@link PdfNameTree}
257224
*/
258225
public PdfNameTree getNameTree(PdfName treeType) {
259226
PdfNameTree tree = nameTrees.get(treeType);
@@ -267,7 +234,7 @@ public PdfNameTree getNameTree(PdfName treeType) {
267234

268235
/**
269236
* This method returns the NumberTree of Page Labels
270-
* @return
237+
* @return returns {@link PdfNumTree}
271238
*/
272239
public PdfNumTree getPageLabelsTree(boolean createIfNotExists) {
273240
if (pageLabels == null && (getPdfObject().containsKey(PdfName.PageLabels) || createIfNotExists)) {
@@ -343,9 +310,10 @@ protected boolean isOCPropertiesMayHaveChanged() {
343310
return ocProperties != null;
344311
}
345312

346-
PdfPage removePage(int pageNum) {
347-
return pageTree.removePage(pageNum);
313+
PdfPagesTree getPageTree() {
314+
return pageTree;
348315
}
316+
349317
/**
350318
* this method return map containing all pages of the document with associated outlines.
351319
*
@@ -476,7 +444,7 @@ PdfDestination copyDestination(PdfObject dest, Map<PdfPage, PdfPage> page2page,
476444
if (oldPage.getPdfObject() == pageObject) {
477445
array.set(0, page2page.get(oldPage).getPdfObject());
478446
d = new PdfStringDestination(name);
479-
toDocument.addNameDestination(name,array);
447+
toDocument.addNamedDestination(name,array);
480448
}
481449
}
482450
}

0 commit comments

Comments
 (0)