Class PDPageLabels
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.PDPageLabels
-
- All Implemented Interfaces:
COSObjectable
public class PDPageLabels extends java.lang.Object implements COSObjectable
Represents the page label dictionary of a document.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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
Fields Modifier and Type Field Description private PDDocument
doc
private java.util.Map<java.lang.Integer,PDPageLabelRange>
labels
-
Constructor Summary
Constructors Constructor Description PDPageLabels(PDDocument document)
Creates an empty page label dictionary for the given document.PDPageLabels(PDDocument document, COSDictionary dict)
Creates an page label dictionary for a document using the information in the given COS dictionary.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
computeLabels(PDPageLabels.LabelHandler handler)
private void
findLabels(PDNumberTreeNode node)
COSBase
getCOSObject()
Convert this standard java object to a COS object.java.lang.String[]
getLabelsByPageIndices()
Returns a mapping with 0-based page indices as keys and corresponding page labels as values as an array.java.util.NavigableSet<java.lang.Integer>
getPageIndices()
Get an ordered set of page indices having a page label range.java.util.Map<java.lang.String,java.lang.Integer>
getPageIndicesByLabels()
Returns a mapping with computed page labels as keys and corresponding 0-based page indices as values.PDPageLabelRange
getPageLabelRange(int startPage)
Returns the page label range starting at the given page, ornull
if no such range is defined.int
getPageRangeCount()
Returns the number of page label ranges.void
setLabelItem(int startPage, PDPageLabelRange item)
Sets the page label range beginning at the specified start page.
-
-
-
Field Detail
-
labels
private java.util.Map<java.lang.Integer,PDPageLabelRange> labels
-
doc
private PDDocument doc
-
-
Constructor Detail
-
PDPageLabels
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
PDDocumentCatalog.setPageLabels(PDPageLabels)
.- Parameters:
document
- The document the page label dictionary is created for.- See Also:
PDDocumentCatalog.setPageLabels(PDPageLabels)
-
PDPageLabels
public PDPageLabels(PDDocument document, COSDictionary dict) throws java.io.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
PDDocumentCatalog.setPageLabels(PDPageLabels)
.- Parameters:
document
- The document the page label dictionary is created for.dict
- an existing page label dictionary- Throws:
java.io.IOException
- If something goes wrong during the number tree conversion.- See Also:
PDDocumentCatalog.setPageLabels(PDPageLabels)
-
-
Method Detail
-
findLabels
private void findLabels(PDNumberTreeNode node) throws java.io.IOException
- Throws:
java.io.IOException
-
getPageRangeCount
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:
- the number of page label ranges.
-
getPageLabelRange
public PDPageLabelRange getPageLabelRange(int startPage)
Returns the page label range starting at the given page, ornull
if no such range is defined.- Parameters:
startPage
- the 0-based page index representing the start page of the page range the item is defined for.- Returns:
- the page label range or
null
if no label range is defined for the given start page.
-
setLabelItem
public void setLabelItem(int startPage, PDPageLabelRange item)
Sets the page label range beginning at the specified start page.- Parameters:
startPage
- the 0-based index of the page representing the start of the page label range.item
- the page label item to set.- Throws:
java.lang.IllegalArgumentException
- if the startPage parameter is < 0.
-
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
getPageIndicesByLabels
public java.util.Map<java.lang.String,java.lang.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:
- a mapping from labels to 0-based page indices.
-
getLabelsByPageIndices
public java.lang.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:
- an array mapping from 0-based page indices to labels.
-
getPageIndices
public java.util.NavigableSet<java.lang.Integer> getPageIndices()
Get an ordered set of page indices having a page label range.- Returns:
- set of page indices.
-
computeLabels
private void computeLabels(PDPageLabels.LabelHandler handler)
-
-