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

public Class PDPageLabels

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.io.IOException, java.util.HashMap, .Iterator, .List, .Map, .NoSuchElementException, .TreeMap, .Map.Entry, .NavigableSet, .TreeSet, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSInteger, .COSName, org.apache.pdfbox.pdmodel.PDDocument

Represents the page label dictionary of a document.
Author
Igor Podolskiy

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PDPageLabels.LabelGenerator

Generates the labels in a page range.

private static interface
PDPageLabels.LabelHandler

Internal interface for the control flow support.

Field Summary

Modifier and TypeField and Description
private final PDDocument
private final Map<Integer, PDPageLabelRange>

Constructor Summary

AccessConstructor and Description
public
PDPageLabels(PDDocument
The document the page label dictionary is created for.
document
)

Creates an empty page label dictionary for the given document.

public
PDPageLabels(PDDocument
The document the page label dictionary is created for.
document
,
COSDictionary
an existing page label dictionary
dict
)

Creates an page label dictionary for a document using the information in the given COS dictionary.

Method Summary

Modifier and TypeMethod and Description
private void
computeLabels(PDPageLabels.LabelHandler handler, int numberOfPages)

private void
public COSBase
getCOSObject()

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

Convert this standard java object to a COS object.

public String[]

Returns:

an array mapping from 0-based page indices to labels.
getLabelsByPageIndices
()

Returns a mapping with 0-based page indices as keys and corresponding page labels as values as an array.

public NavigableSet<Integer>

Returns:

set of page indices.
getPageIndices
()

Get an ordered set of page indices having a page label range.

public Map<String, Integer>

Returns:

a mapping from labels to 0-based page indices.
getPageIndicesByLabels
()

Returns a mapping with computed page labels as keys and corresponding 0-based page indices as values.

public PDPageLabelRange

Returns:

the page label range or null if no label range is defined for the given start page.
getPageLabelRange
(int
the 0-based page index representing the start page of the page range the item is defined for.
startPage
)

Returns the page label range starting at the given page, or null if no such range is defined.

public int

Returns:

the number of page label ranges.
getPageRangeCount
()

Returns the number of page label ranges.

public void
setLabelItem(int
the 0-based index of the page representing the start of the page label range.
startPage
,
PDPageLabelRange
the page label item to set.
item
)

Sets the page label range beginning at the specified start page.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

docback to summary
private final PDDocument doc
labelsback to summary
private final Map<Integer, PDPageLabelRange> labels

Constructor Detail

PDPageLabelsback to summary
public PDPageLabels(PDDocument document)

Creates an empty page label dictionary for the given document.

Note that the page label dictionary won't be automatically added to the document; you will still need to do it manually (see org.apache.pdfbox.pdmodel.PDDocumentCatalog#setPageLabels(PDPageLabels).

Parameters
document:PDDocument

The document the page label dictionary is created for.

See Also
org.apache.pdfbox.pdmodel.PDDocumentCatalog#setPageLabels(PDPageLabels)
PDPageLabelsback to summary
public PDPageLabels(PDDocument document, COSDictionary dict) throws IOException

Creates an page label dictionary for a document using the information in the given COS dictionary.

Note that the page label dictionary won't be automatically added to the document; you will still need to do it manually (see org.apache.pdfbox.pdmodel.PDDocumentCatalog#setPageLabels(PDPageLabels).

Parameters
document:PDDocument

The document the page label dictionary is created for.

dict:COSDictionary

an existing page label dictionary

Exceptions
IOException:
If something goes wrong during the number tree conversion.
See Also
org.apache.pdfbox.pdmodel.PDDocumentCatalog#setPageLabels(PDPageLabels)

Method Detail

computeLabelsback to summary
private void computeLabels(PDPageLabels.LabelHandler handler, int numberOfPages)
findLabelsback to summary
private void findLabels(PDNumberTreeNode node) throws IOException
getCOSObjectback to summary
public COSBase 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:COSBase

The cos object that matches this Java object.

Annotations
@Override
getLabelsByPageIndicesback to summary
public String[] getLabelsByPageIndices()

Returns a mapping with 0-based page indices as keys and corresponding page labels as values as an array. The array will have exactly as much entries as the document has pages.

Returns:String[]

an array mapping from 0-based page indices to labels.

getPageIndicesback to summary
public NavigableSet<Integer> getPageIndices()

Get an ordered set of page indices having a page label range.

Returns:NavigableSet<Integer>

set of page indices.

getPageIndicesByLabelsback to summary
public Map<String, Integer> getPageIndicesByLabels()

Returns a mapping with computed page labels as keys and corresponding 0-based page indices as values. The returned map will contain at most as much entries as the document has pages.

Note

If the document contains duplicate page labels, the returned map will contain less entries than the document has pages. The page index returned in this case is the highest index among all pages sharing the same label.

Returns:Map<String, Integer>

a mapping from labels to 0-based page indices.

getPageLabelRangeback to summary
public PDPageLabelRange getPageLabelRange(int startPage)

Returns the page label range starting at the given page, or null if no such range is defined.

Parameters
startPage:int

the 0-based page index representing the start page of the page range the item is defined for.

Returns:PDPageLabelRange

the page label range or null if no label range is defined for the given start page.

getPageRangeCountback to summary
public int getPageRangeCount()

Returns the number of page label ranges.

This will be always >= 1, as the required default entry for the page range starting at the first page is added automatically by this implementation (see PDF32000-1:2008, p. 375).

Returns:int

the number of page label ranges.

setLabelItemback to summary
public void setLabelItem(int startPage, PDPageLabelRange item)

Sets the page label range beginning at the specified start page.

Parameters
startPage:int

the 0-based index of the page representing the start of the page label range.

item:PDPageLabelRange

the page label item to set.

Exceptions
IllegalArgumentException:
if the startPage parameter is < 0.
org.apache.pdfbox.pdmodel.common back to summary

private Class PDPageLabels.LabelGenerator

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

Generates the labels in a page range.
Author
Igor Podolskiy

Field Summary

Modifier and TypeField and Description
private int
private final PDPageLabelRange
private final int
private static final String[][]
ROMANS

Lookup table used by the makeRomanLabel(int) method.

Constructor Summary

AccessConstructor and Description
pack-priv
LabelGenerator(PDPageLabelRange label, int pages)

Method Summary

Modifier and TypeMethod and Description
private String
getNumber(int pageIndex, String style)

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

private static String
makeLetterLabel(int num)

a..z, aa..zz, aaa..zzz ...

private static String
makeRomanLabel(int pageIndex)

public String
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

currentPageback to summary
private int currentPage
labelInfoback to summary
private final PDPageLabelRange labelInfo
numPagesback to summary
private final int numPages
ROMANSback to summary
private static final String[][] ROMANS

Lookup table used by the makeRomanLabel(int) method.

Constructor Detail

LabelGeneratorback to summary
pack-priv LabelGenerator(PDPageLabelRange label, int pages)

Method Detail

getNumberback to summary
private String getNumber(int pageIndex, String style)
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
makeLetterLabelback to summary
private static String makeLetterLabel(int num)

a..z, aa..zz, aaa..zzz ... labeling as described in PDF32000-1:2008, Table 159, Page 375.

makeRomanLabelback to summary
private static String makeRomanLabel(int pageIndex)
nextback to summary
public String next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:String

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.common back to summary

private Interface PDPageLabels.LabelHandler


Internal interface for the control flow support.
Author
Igor Podolskiy

Method Summary

Modifier and TypeMethod and Description
public void
newLabel(int pageIndex, String label)

Method Detail

newLabelback to summary
public void newLabel(int pageIndex, String label)