java.lang.Object
org.sejda.sambox.pdmodel.PDPageTree
- All Implemented Interfaces:
Iterable<PDPage>,COSObjectable
The page tree, which defines the ordering of pages in the document in an efficient manner.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classIterator which walks all the nodes in the tree.static classA tuple of a page and the parent found when traversing the page tree top down.private final classIterator which walks all pages in the tree, in order.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PDDocumentprivate static final org.slf4j.Loggerprivate final COSDictionary -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for embedding.PDPageTree(COSDictionary root) Constructor for reading.PDPageTree(COSDictionary root, PDDocument document) Constructor for reading. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given page to this page tree.private booleanfindPage(PDPageTree.SearchContext context, COSDictionary node) get(int index) Returns the page at the given index.private PDPageTree.PageAndPageTreeParentget(int pageNum, COSDictionary node, int encountered, COSDictionary pageTreeParent, Set<COSDictionary> visited) Returns the given COS page using a depth-first search.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.getInheritableAttribute(COSDictionary node, COSName key, Class<T> clazz) Similar togetInheritableAttribute(COSDictionary, COSName)but also checks the returned element matches the expected type classstatic COSBasegetInheritableAttribute(COSDictionary node, COSName key, Set<String> visitedObjectIds) private List<COSDictionary>getKids(COSDictionary node) Helper to get kids from malformed PDFs.private Stringprivate voidincreaseParents(COSDictionary parentDict) intReturns 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.static booleanisPageTreeNode(COSDictionary node) 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.private voidremove(COSDictionary node) Removes the given COS page.private voidremove(COSDictionary node, COSDictionary knownParent) Removes the given COS page.voidRemoves the given page from the page tree.private static voidsanitizeType(COSDictionary dictionary) stream()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
root
-
document
-
-
Constructor Details
-
PDPageTree
public PDPageTree()Constructor for embedding. -
PDPageTree
Constructor for reading.- Parameters:
root- A page tree root.
-
PDPageTree
PDPageTree(COSDictionary root, PDDocument document) Constructor for reading.- Parameters:
root- A page tree root.document- The document which contains "root".
-
-
Method Details
-
getInheritableAttribute
public static <T extends COSBase> COSBase getInheritableAttribute(COSDictionary node, COSName key, Class<T> clazz) Similar togetInheritableAttribute(COSDictionary, COSName)but also checks the returned element matches the expected type class- Type Parameters:
T-- Parameters:
node-key-clazz- expected type class- Returns:
-
getInheritableAttribute
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
-
getInheritableAttribute
public static COSBase getInheritableAttribute(COSDictionary node, COSName key, Set<String> visitedObjectIds) -
iterator
Returns an iterator which walks all pages in the tree, in order. -
stream
- Returns:
- a sequential
Streamover the pages of this page tree.
-
streamNodes
- Returns:
- a sequential
Streamover the nodes of this page tree.
-
getKids
Helper to get kids from malformed PDFs.- Parameters:
node- page tree node- Returns:
- list of kids
-
get
Returns the page at the given index.- Parameters:
index- zero-based index
-
sanitizeType
-
get
private PDPageTree.PageAndPageTreeParent get(int pageNum, COSDictionary node, int encountered, COSDictionary pageTreeParent, Set<COSDictionary> visited) Returns the given COS page using a depth-first search.- Parameters:
pageNum- 1-based page numbernode- page tree node to searchencountered- number of pages encountered so farpageTreeParent- the parent node, as determined traversing the page tree top -> down- Returns:
- COS dictionary of the Page object
-
getSourcePath
-
isPageTreeNode
- Returns:
- true if the node is a page tree node (i.e. and intermediate).
-
indexOf
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.
-
findPage
-
getCount
public int getCount()Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree. -
getCOSObject
- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The
COSBasethat 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
Removes the given page from the page tree.- Parameters:
page- The page to remove.
-
remove
Removes the given COS page. -
remove
Removes the given COS page. -
add
Adds the given page to this page tree.- Parameters:
page- The page to add.
-
insertBefore
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
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.
-
increaseParents
-