Package com.tom_roush.pdfbox.pdmodel
Class PDPageTree
- java.lang.Object
-
- com.tom_roush.pdfbox.pdmodel.PDPageTree
-
- All Implemented Interfaces:
COSObjectable,Iterable<PDPage>
public class PDPageTree extends Object implements COSObjectable, Iterable<PDPage>
The page tree, which defines the ordering of pages in the document in an efficient manner.
-
-
Constructor Summary
Constructors Constructor Description PDPageTree()Constructor for embedding.PDPageTree(COSDictionary root)Constructor for reading.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(PDPage page)Adds the given page to this page tree.PDPageget(int index)Returns the page at the given index.COSDictionarygetCOSObject()Convert this standard java object to a COS object.intgetCount()Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree.static COSBasegetInheritableAttribute(COSDictionary node, COSName key)Returns the given attribute, inheriting from parent tree nodes if necessary.intindexOf(PDPage page)Returns the index of the given page, or -1 if it does not exist.voidinsertAfter(PDPage newPage, PDPage prevPage)Insert a page after another page within a page tree.voidinsertBefore(PDPage newPage, PDPage nextPage)Insert a page before another page within a page tree.Iterator<PDPage>iterator()Returns an iterator which walks all pages in the tree, in order.voidremove(int index)Removes the page with the given index from the page tree.voidremove(PDPage page)Removes the given page from the page tree.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
PDPageTree
public PDPageTree()
Constructor for embedding.
-
PDPageTree
public PDPageTree(COSDictionary root)
Constructor for reading.- Parameters:
root- A page tree root.
-
-
Method Detail
-
getInheritableAttribute
public static COSBase getInheritableAttribute(COSDictionary node, COSName key)
Returns the given attribute, inheriting from parent tree nodes if necessary.- Parameters:
node- page objectkey- the key to look up- Returns:
- COS value for the given key
-
iterator
public Iterator<PDPage> iterator()
Returns an iterator which walks all pages in the tree, in order.
-
get
public PDPage get(int index)
Returns the page at the given index.- Parameters:
index- zero-based index- Throws:
IllegalStateException- if the requested index isn't found or doesn't point to a valid page dictionaryIndexOutOfBoundsException- if the requested index is higher than the page count
-
indexOf
public int indexOf(PDPage page)
Returns the index of the given page, or -1 if it does not exist.- Parameters:
page- The page to search for.- Returns:
- the zero-based index of the given page, or -1 if the page is not found.
-
getCount
public int getCount()
Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree.- Returns:
- the number of leaf nodes.
-
getCOSObject
public COSDictionary getCOSObject()
Description copied from interface:COSObjectableConvert this standard java object to a COS object.- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The cos object that matches this Java object.
-
remove
public void remove(int index)
Removes the page with the given index from the page tree.- Parameters:
index- zero-based page index
-
remove
public void remove(PDPage page)
Removes the given page from the page tree.- Parameters:
page- The page to remove.
-
add
public void add(PDPage page)
Adds the given page to this page tree.- Parameters:
page- The page to add.
-
insertBefore
public void insertBefore(PDPage newPage, PDPage nextPage)
Insert a page before another page within a page tree.- Parameters:
newPage- the page to be inserted.nextPage- the page that is to be after the new page.- Throws:
IllegalArgumentException- if one attempts to insert a page that isn't part of a page tree.
-
insertAfter
public void insertAfter(PDPage newPage, PDPage prevPage)
Insert a page after another page within a page tree.- Parameters:
newPage- the page to be inserted.prevPage- the page that is to be before the new page.- Throws:
IllegalArgumentException- if one attempts to insert a page that isn't part of a page tree.
-
-