Top Description Inners Fields Constructors Methods
org.apache.pdfbox.pdmodel

public Class PDPageTree

extends Object
implements COSObjectable, Iterable<PDPage>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable, org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.util.ArrayDeque, .Iterator, .Queue, .ArrayList, .HashSet, .List, .NoSuchElementException, .Set, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSInteger, .COSName, org.apache.pdfbox.pdmodel.common.COSObjectable, org.apache.commons.logging.Log, .LogFactory

The page tree, which defines the ordering of pages in the document in an efficient manner.
Author
John Hewson

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PDPageTree.PageIterator

Iterator which walks all pages in the tree, in order.

private static class

Field Summary

Modifier and TypeField and Description
private final PDDocument
private static final Log
private final Set<COSDictionary>
private final COSDictionary

Constructor Summary

AccessConstructor and Description
public
PDPageTree()

Constructor for embedding.

public
PDPageTree(COSDictionary
A page tree root.
root
)

Constructor for reading.

pack-priv
PDPageTree(COSDictionary
A page tree root.
root
,
PDDocument
The document which contains "root".
document
)

Constructor for reading.

Method Summary

Modifier and TypeMethod and Description
public void
add(PDPage
The page to add.
page
)

Adds the given page to this page tree.

private boolean
public PDPage

Returns:

the page at the given index
get
(int
zero-based index
index
)

Returns the page at the given index.

private COSDictionary

Returns:

COS dictionary of the Page object
get
(int
1-based page number
pageNum
,
COSDictionary
page tree node to search
node
,
int
number of pages encountered so far
encountered
)

Returns the given COS page using a depth-first search.

public COSDictionary
getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

public int

Returns:

the number of leaf nodes, 0 if not present
getCount
()

Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree.

public static COSBase

Returns:

COS value for the given key
getInheritableAttribute
(COSDictionary
page object
node
,
COSName
the key to look up
key
)

Returns the given attribute, inheriting from parent tree nodes if necessary.

private List<COSDictionary>

Returns:

list of kids
getKids
(COSDictionary
page tree node
node
)

Helper to get kids from malformed PDFs.

private void
public int

Returns:

the zero-based index of the given page, or -1 if the page is not found.
indexOf
(PDPage
The page to search for.
page
)

Returns the index of the given page, or -1 if it does not exist.

public void
insertAfter(PDPage
the page to be inserted.
newPage
,
PDPage
the page that is to be before the new page.
prevPage
)

Insert a page after another page within a page tree.

public void
insertBefore(PDPage
the page to be inserted.
newPage
,
PDPage
the page that is to be after the new page.
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. and intermediate).

public Iterator<PDPage>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator which walks all pages in the tree, in order.

public void
remove(int
zero-based page index
index
)

Removes the page with the given index from the page tree.

public void
remove(PDPage
The page to remove.
page
)

Removes the given page from the page tree.

private void
remove(COSDictionary node)

Removes the given COS page.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

documentback to summary
private final PDDocument document
LOGback to summary
private static final Log LOG
pageSetback to summary
private final Set<COSDictionary> pageSet
rootback to summary
private final COSDictionary root

Constructor Detail

PDPageTreeback to summary
public PDPageTree()

Constructor for embedding.

PDPageTreeback to summary
public PDPageTree(COSDictionary root)

Constructor for reading.

Parameters
root:COSDictionary

A page tree root.

PDPageTreeback to summary
pack-priv PDPageTree(COSDictionary root, PDDocument document)

Constructor for reading.

Parameters
root:COSDictionary

A page tree root.

document:PDDocument

The document which contains "root".

Method Detail

addback to summary
public void add(PDPage page)

Adds the given page to this page tree.

Parameters
page:PDPage

The page to add.

findPageback to summary
private boolean findPage(PDPageTree.SearchContext context, COSDictionary node)
getback to summary
public PDPage get(int index)

Returns the page at the given index.

Parameters
index:int

zero-based index

Returns:PDPage

the page at the given index

Exceptions
IllegalStateException:
if the requested index isn't found or doesn't point to a valid page dictionary
IndexOutOfBoundsException:
if the requested index is higher than the page count
getback to summary
private COSDictionary get(int pageNum, COSDictionary node, int encountered)

Returns the given COS page using a depth-first search.

Parameters
pageNum:int

1-based page number

node:COSDictionary

page tree node to search

encountered:int

number of pages encountered so far

Returns:COSDictionary

COS dictionary of the Page object

Exceptions
IllegalStateException:
if the requested page number isn't found
IndexOutOfBoundsException:
if the requested page number is higher than the page count
getCOSObjectback to summary
public COSDictionary getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Doc from org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

Returns:COSDictionary

The cos object that matches this Java object.

Annotations
@Override
getCountback to summary
public int getCount()

Returns the number of leaf nodes (page objects) that are descendants of this root within the page tree.

Returns:int

the number of leaf nodes, 0 if not present

getInheritableAttributeback to summary
public static COSBase getInheritableAttribute(COSDictionary node, COSName key)

Returns the given attribute, inheriting from parent tree nodes if necessary.

Parameters
node:COSDictionary

page object

key:COSName

the key to look up

Returns:COSBase

COS value for the given key

getKidsback to summary
private List<COSDictionary> getKids(COSDictionary node)

Helper to get kids from malformed PDFs.

Parameters
node:COSDictionary

page tree node

Returns:List<COSDictionary>

list of kids

increaseParentsback to summary
private void increaseParents(COSDictionary parentDict)
indexOfback to summary
public int indexOf(PDPage page)

Returns the index of the given page, or -1 if it does not exist.

Parameters
page:PDPage

The page to search for.

Returns:int

the zero-based index of the given page, or -1 if the page is not found.

insertAfterback to summary
public void insertAfter(PDPage newPage, PDPage prevPage)

Insert a page after another page within a page tree.

Parameters
newPage:PDPage

the page to be inserted.

prevPage:PDPage

the page that is to be before the new page.

Exceptions
IllegalArgumentException:
if one attempts to insert a page that isn't part of a page tree.
insertBeforeback to summary
public void insertBefore(PDPage newPage, PDPage nextPage)

Insert a page before another page within a page tree.

Parameters
newPage:PDPage

the page to be inserted.

nextPage:PDPage

the page that is to be after the new page.

Exceptions
IllegalArgumentException:
if one attempts to insert a page that isn't part of a page tree.
isPageTreeNodeback to summary
private boolean isPageTreeNode(COSDictionary node)

Returns true if the node is a page tree node (i.e. and intermediate).

iteratorback to summary
public Iterator<PDPage> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator which walks all pages in the tree, in order.

Returns:Iterator<PDPage>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
removeback to summary
public void remove(int index)

Removes the page with the given index from the page tree.

Parameters
index:int

zero-based page index

removeback to summary
public void remove(PDPage page)

Removes the given page from the page tree.

Parameters
page:PDPage

The page to remove.

removeback to summary
private void remove(COSDictionary node)

Removes the given COS page.

sanitizeTypeback to summary
private static void sanitizeType(COSDictionary dictionary)
org.apache.pdfbox.pdmodel back to summary

private final Class PDPageTree.PageIterator

extends Object
implements Iterator<PDPage>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Iterator which walks all pages in the tree, in order.

Field Summary

Modifier and TypeField and Description
private final Queue<COSDictionary>
private Set<COSDictionary>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public PDPage
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

queueback to summary
private final Queue<COSDictionary> queue
setback to summary
private Set<COSDictionary> set

Constructor Detail

PageIteratorback to summary
private PageIterator(COSDictionary node)

Method Detail

enqueueKidsback to summary
private void enqueueKids(COSDictionary node)
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public PDPage next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:PDPage

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
org.apache.pdfbox.pdmodel back to summary

private final Class PDPageTree.SearchContext

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private int
private final COSDictionary

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

foundback to summary
private boolean found
indexback to summary
private int index
searchedback to summary
private final COSDictionary searched

Constructor Detail

SearchContextback to summary
private SearchContext(PDPage page)

Method Detail

visitPageback to summary
private void visitPage(COSDictionary current)