public class PDPageTree extends java.lang.Object implements COSObjectable, java.lang.Iterable<PDPage>
Modifier and Type | Class and Description |
---|---|
private class |
PDPageTree.PageIterator
Iterator which walks all pages in the tree, in order.
|
private static class |
PDPageTree.SearchContext |
Modifier and Type | Field and Description |
---|---|
private PDDocument |
document |
private static org.apache.commons.logging.Log |
LOG |
private COSDictionary |
root |
Constructor and Description |
---|
PDPageTree()
Constructor for embedding.
|
PDPageTree(COSDictionary root)
Constructor for reading.
|
PDPageTree(COSDictionary root,
PDDocument document)
Constructor for reading.
|
Modifier and Type | Method and Description |
---|---|
void |
add(PDPage page)
Adds the given page to this page tree.
|
private boolean |
findPage(PDPageTree.SearchContext context,
COSDictionary node) |
PDPage |
get(int index)
Returns the page at the given index.
|
private COSDictionary |
get(int pageNum,
COSDictionary node,
int encountered)
Returns the given COS page using a depth-first search.
|
COSDictionary |
getCOSObject()
Convert this standard java object to a COS object.
|
int |
getCount()
Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree.
|
static COSBase |
getInheritableAttribute(COSDictionary node,
COSName key)
Returns the given attribute, inheriting from parent tree nodes if necessary.
|
private java.util.List<COSDictionary> |
getKids(COSDictionary node)
Helper to get kids from malformed PDFs.
|
private void |
increaseParents(COSDictionary parentDict) |
int |
indexOf(PDPage page)
Returns the index of the given page, or -1 if it does not exist.
|
void |
insertAfter(PDPage newPage,
PDPage prevPage)
Insert a page after another page within a page tree.
|
void |
insertBefore(PDPage newPage,
PDPage nextPage)
Insert a page before another page within a page tree.
|
private boolean |
isPageTreeNode(COSDictionary node)
Returns true if the node is a page tree node (i.e.
|
java.util.Iterator<PDPage> |
iterator()
Returns an iterator which walks all pages in the tree, in order.
|
private void |
remove(COSDictionary node)
Removes the given COS page.
|
void |
remove(int index)
Removes the page with the given index from the page tree.
|
void |
remove(PDPage page)
Removes the given page from the page tree.
|
private static void |
sanitizeType(COSDictionary dictionary) |
private static final org.apache.commons.logging.Log LOG
private final COSDictionary root
private final PDDocument document
public PDPageTree()
public PDPageTree(COSDictionary root)
root
- A page tree root.PDPageTree(COSDictionary root, PDDocument document)
root
- A page tree root.document
- The document which contains "root".public static COSBase getInheritableAttribute(COSDictionary node, COSName key)
node
- page objectkey
- the key to look uppublic java.util.Iterator<PDPage> iterator()
iterator
in interface java.lang.Iterable<PDPage>
private java.util.List<COSDictionary> getKids(COSDictionary node)
node
- page tree nodepublic PDPage get(int index)
index
- zero-based indexprivate static void sanitizeType(COSDictionary dictionary)
private COSDictionary get(int pageNum, COSDictionary node, int encountered)
pageNum
- 1-based page numbernode
- page tree node to searchencountered
- number of pages encountered so farprivate boolean isPageTreeNode(COSDictionary node)
public int indexOf(PDPage page)
page
- The page to search for.private boolean findPage(PDPageTree.SearchContext context, COSDictionary node)
public int getCount()
public COSDictionary getCOSObject()
COSObjectable
getCOSObject
in interface COSObjectable
public void remove(int index)
index
- zero-based page indexpublic void remove(PDPage page)
page
- The page to remove.private void remove(COSDictionary node)
public void add(PDPage page)
page
- The page to add.public void insertBefore(PDPage newPage, PDPage nextPage)
newPage
- the page to be inserted.nextPage
- the page that is to be after the new page.java.lang.IllegalArgumentException
- if one attempts to insert a page that isn't part of a page
tree.public void insertAfter(PDPage newPage, PDPage prevPage)
newPage
- the page to be inserted.prevPage
- the page that is to be before the new page.java.lang.IllegalArgumentException
- if one attempts to insert a page that isn't part of a page
tree.private void increaseParents(COSDictionary parentDict)