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

public Class PDPage

extends Object
implements COSObjectable, PDContentStream
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.contentstream.PDContentStream, org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, java.util.ArrayList, .Iterator, .List, java.util.stream.Collectors, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.contentstream.PDContentStream, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSFloat, .COSName, .COSNumber, .COSObject, .COSStream, org.apache.pdfbox.filter.FlateFilterDecoderStream, org.apache.pdfbox.io.NonSeekableRandomAccessReadInputStream, .RandomAccessInputStream, .RandomAccessRead, .RandomAccessReadBuffer, .SequenceRandomAccessRead, org.apache.pdfbox.pdmodel.common.COSArrayList, .COSObjectable, .PDMetadata, .PDRectangle, .PDStream, org.apache.pdfbox.pdmodel.interactive.action.PDPageAdditionalActions, org.apache.pdfbox.pdmodel.interactive.annotation.AnnotationFilter, .PDAnnotation, org.apache.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary, org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead, .PDTransition, org.apache.pdfbox.util.Matrix

A page in a PDF document.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private static final byte[]
private static final Log
LOG

Log instance

private PDRectangle
private final COSDictionary
private PDResources
private ResourceCache

Constructor Summary

AccessConstructor and Description
public
PDPage()

Creates a new PDPage instance for embedding, with a size of U.S.

public
PDPage(PDRectangle
The MediaBox of the page.
mediaBox
)

Creates a new instance of PDPage for embedding.

public
PDPage(COSDictionary
A page dictionary in a PDF document.
pageDictionary
)

Creates a new instance of PDPage for reading.

pack-priv
PDPage(COSDictionary
A page dictionary in a PDF document.
pageDictionary
,
ResourceCache resourceCache)

Creates a new instance of PDPage for reading.

Method Summary

Modifier and TypeMethod and Description
private PDRectangle
clipToMediaBox(PDRectangle box)

Clips the given box to the bounds of the media box.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public PDPageAdditionalActions

Returns:

The Actions for this Page
getActions
()

Get the page actions.

public List<PDAnnotation>

Returns:

List of the PDAnnotation objects, never null. The returned list is backed by the annotations COSArray, so any adding or deleting in this list will change the document too.
getAnnotations
()

This will return a list of the annotations for this page.

public List<PDAnnotation>

Returns:

List of the PDAnnotation objects, never null. The returned list is backed by the annotations COSArray, so any adding or deleting in this list will change the document too.
getAnnotations
(AnnotationFilter
the annotation filter provided allowing to filter out specific annotations
annotationFilter
)

This will return a list of the annotations for this page.

public PDRectangle

Returns:

The ArtBox attribute.
getArtBox
()

A rectangle, expressed in default user space units, defining the extent of the page's meaningful content (including potential white space) as intended by the page's creator The default is the CropBox.

public PDRectangle
getBBox()

Implements org.apache.pdfbox.contentstream.PDContentStream.getBBox.

Returns the bounding box of the contents.

public PDRectangle

Returns:

The BleedBox attribute.
getBleedBox
()

A rectangle, expressed in default user space units, defining the region to which the contents of the page should be clipped when output in a production environment.

public InputStream

Returns:

An InputStream, never null. Multiple content streams are concatenated and separated with a newline. An empty stream is returned if the page doesn't have any content stream.
getContents
()

Implements org.apache.pdfbox.contentstream.PDContentStream.getContents.

Returns the content stream(s) of this page as a single input stream.

public RandomAccessRead
public RandomAccessRead
public Iterator<PDStream>

Returns:

content stream iterator
getContentStreams
()

Returns the content streams which make up this page.

public COSDictionary

Returns:

The cos object that matches this Java object.
getCOSObject
()

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

Convert this standard java object to a COS object.

public PDRectangle

Returns:

the cropbox of the page
getCropBox
()

A rectangle, expressed in default user space units, defining the visible region of default user space.

public Matrix
getMatrix()

Implements org.apache.pdfbox.contentstream.PDContentStream.getMatrix.

Returns the matrix which transforms from the stream's space to user space.

public PDRectangle

Returns:

the media box of the page
getMediaBox
()

A rectangle, expressed in default user space units, defining the boundaries of the physical medium on which the page is intended to be displayed or printed.

public PDMetadata

Returns:

The metadata for this object.
getMetadata
()

Get the metadata that is part of the document catalog.

public ResourceCache

Returns:

the resource cache of the current page
getResourceCache
()

Returns the resource cache associated with this page, or null if there is none.

public PDResources
getResources()

Implements org.apache.pdfbox.contentstream.PDContentStream.getResources.

A dictionary containing any resources required by the page.

public int

Returns:

The rotation angle in degrees in normalized form (0, 90, 180 or 270) or 0 if invalid or not set at this level.
getRotation
()

Returns the rotation angle in degrees by which the page should be rotated clockwise when displayed or printed.

public int

Returns:

the integer key of the page's entry in the structural parent tree or -1 if there isn't any.
getStructParents
()

This will get the key of this Page in the structural parent tree.

public List<PDThreadBead>

Returns:

A list of article threads on this page, never null. The returned list is backed by the beads COSArray, so any adding or deleting in this list will change the document too.
getThreadBeads
()

This will get a list of PDThreadBead objects, which are article threads in the document.

public PDTransition

Returns:

The page transition associated with this page or null if no transition is defined
getTransition
()

public PDRectangle

Returns:

The TrimBox attribute.
getTrimBox
()

A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming.

public float

Returns:

the user unit.
getUserUnit
()

Get the user unit.

public List<PDViewportDictionary>

Returns:

a list of viewports or null if there is no /VP entry.
getViewports
()

Get the viewports.

public boolean

Returns:

true if the page has a non empty content stream, otherwise false
hasContents
()

Returns true if this page has one or more content streams.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
setActions(PDPageAdditionalActions
The actions for the page.
actions
)

Set the page actions.

public void
setAnnotations(List<PDAnnotation>
The new list of annotations.
annotations
)

This will set the list of annotations.

public void
setArtBox(PDRectangle
The new ArtBox for this page.
artBox
)

This will set the ArtBox for this page.

public void
setBleedBox(PDRectangle
The new BleedBox for this page.
bleedBox
)

This will set the BleedBox for this page.

public void
setContents(PDStream
The new contents of the page.
contents
)

This will set the contents of this page.

public void
setContents(List<PDStream>
Array of new contents of the page.
contents
)

This will set the contents of this page.

public void
setCropBox(PDRectangle
The new CropBox for this page.
cropBox
)

This will set the CropBox for this page.

public void
setMediaBox(PDRectangle
The new mediaBox for this page.
mediaBox
)

This will set the mediaBox for this page.

public void
setMetadata(PDMetadata
The meta data for this object.
meta
)

Set the metadata for this object.

public void
setResources(PDResources
The new resources for this page.
resources
)

This will set the resources for this page.

public void
setRotation(int
The new rotation for this page in degrees.
rotation
)

This will set the rotation for this page.

public void
setStructParents(int
The new key for this page.
structParents
)

This will set the key for this page in the structural parent tree.

public void
setThreadBeads(List<PDThreadBead>
A list of PDThreadBead objects or null.
beads
)

This will set the list of thread beads.

public void
setTransition(PDTransition
The new transition to set on this page.
transition
)

public void
setTransition(PDTransition
The new transition to set on this page.
transition
,
float
The maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.
duration
)

Convenient method to set a transition and the display duration

public void
setTrimBox(PDRectangle
The new TrimBox for this page.
trimBox
)

This will set the TrimBox for this page.

public void
setUserUnit(float
throws IllegalArgumentException if the parameter is not positive.
userUnit
)

Get the user unit.

public void
setViewports(List<PDViewportDictionary>
A list of viewports, or null if the entry is to be deleted.
viewports
)

Set the viewports.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

DELIMITERback to summary
private static final byte[] DELIMITER
LOGback to summary
private static final Log LOG

Log instance

mediaBoxback to summary
private PDRectangle mediaBox
pageback to summary
private final COSDictionary page
pageResourcesback to summary
private PDResources pageResources
resourceCacheback to summary
private ResourceCache resourceCache

Constructor Detail

PDPageback to summary
public PDPage()

Creates a new PDPage instance for embedding, with a size of U.S. Letter (8.5 x 11 inches).

PDPageback to summary
public PDPage(PDRectangle mediaBox)

Creates a new instance of PDPage for embedding.

Parameters
mediaBox:PDRectangle

The MediaBox of the page.

PDPageback to summary
public PDPage(COSDictionary pageDictionary)

Creates a new instance of PDPage for reading.

Parameters
pageDictionary:COSDictionary

A page dictionary in a PDF document.

PDPageback to summary
pack-priv PDPage(COSDictionary pageDictionary, ResourceCache resourceCache)

Creates a new instance of PDPage for reading.

Parameters
pageDictionary:COSDictionary

A page dictionary in a PDF document.

Method Detail

clipToMediaBoxback to summary
private PDRectangle clipToMediaBox(PDRectangle box)

Clips the given box to the bounds of the media box.

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getActionsback to summary
public PDPageAdditionalActions getActions()

Get the page actions.

Returns:PDPageAdditionalActions

The Actions for this Page

getAnnotationsback to summary
public List<PDAnnotation> getAnnotations() throws IOException

This will return a list of the annotations for this page.

Returns:List<PDAnnotation>

List of the PDAnnotation objects, never null. The returned list is backed by the annotations COSArray, so any adding or deleting in this list will change the document too.

Exceptions
IOException:
If there is an error while creating the annotation list.
getAnnotationsback to summary
public List<PDAnnotation> getAnnotations(AnnotationFilter annotationFilter) throws IOException

This will return a list of the annotations for this page.

Parameters
annotationFilter:AnnotationFilter

the annotation filter provided allowing to filter out specific annotations

Returns:List<PDAnnotation>

List of the PDAnnotation objects, never null. The returned list is backed by the annotations COSArray, so any adding or deleting in this list will change the document too.

Exceptions
IOException:
If there is an error while creating the annotation list.
getArtBoxback to summary
public PDRectangle getArtBox()

A rectangle, expressed in default user space units, defining the extent of the page's meaningful content (including potential white space) as intended by the page's creator The default is the CropBox.

Returns:PDRectangle

The ArtBox attribute.

getBBoxback to summary
public PDRectangle getBBox()

Implements org.apache.pdfbox.contentstream.PDContentStream.getBBox.

Doc from org.apache.pdfbox.contentstream.PDContentStream.getBBox.

Returns the bounding box of the contents.

Returns:PDRectangle

the bounding box of the content stream or null

Annotations
@Override
getBleedBoxback to summary
public PDRectangle getBleedBox()

A rectangle, expressed in default user space units, defining the region to which the contents of the page should be clipped when output in a production environment. The default is the CropBox.

Returns:PDRectangle

The BleedBox attribute.

getContentsback to summary
public InputStream getContents() throws IOException

Implements org.apache.pdfbox.contentstream.PDContentStream.getContents.

Returns the content stream(s) of this page as a single input stream.

Returns:InputStream

An InputStream, never null. Multiple content streams are concatenated and separated with a newline. An empty stream is returned if the page doesn't have any content stream.

Annotations
@Override
Exceptions
IOException:
If the stream could not be read
getContentsForRandomAccessback to summary
public RandomAccessRead getContentsForRandomAccess() throws IOException

Implements org.apache.pdfbox.contentstream.PDContentStream.getContentsForRandomAccess.

Doc from org.apache.pdfbox.contentstream.PDContentStream.getContentsForRandomAccess.

Returns this stream's content, if any.

Returns:RandomAccessRead

A RandomAccessRead or null.

Annotations
@Override
Exceptions
IOException:
If the content could not be read
getContentsForStreamParsingback to summary
public RandomAccessRead getContentsForStreamParsing() throws IOException

Overrides default org.apache.pdfbox.contentstream.PDContentStream.getContentsForStreamParsing.

Doc from org.apache.pdfbox.contentstream.PDContentStream.getContentsForStreamParsing.

Returns this stream's content, if any. The random access capabilities of the returned instance is supposed to be limited. Peek/rewind operations are limited to a small range of data and not the whole set of data. Seek operations aren't supported at all.

Returns:RandomAccessRead

A RandomAccessRead or null.

Annotations
@Override
Exceptions
IOException:
If the content could not be read
getContentStreamsback to summary
public Iterator<PDStream> getContentStreams()

Returns the content streams which make up this page.

Returns:Iterator<PDStream>

content stream iterator

getCOSObjectback to summary
public COSDictionary getCOSObject()

Implements 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
getCropBoxback to summary
public PDRectangle getCropBox()

A rectangle, expressed in default user space units, defining the visible region of default user space. When the page is displayed or printed, its contents are to be clipped (cropped) to this rectangle.

Returns:PDRectangle

the cropbox of the page

getMatrixback to summary
public Matrix getMatrix()

Implements org.apache.pdfbox.contentstream.PDContentStream.getMatrix.

Doc from org.apache.pdfbox.contentstream.PDContentStream.getMatrix.

Returns the matrix which transforms from the stream's space to user space.

Returns:Matrix

the matrix of the content stream or the identity matrix if there isn't any

Annotations
@Override
getMediaBoxback to summary
public PDRectangle getMediaBox()

A rectangle, expressed in default user space units, defining the boundaries of the physical medium on which the page is intended to be displayed or printed.

Returns:PDRectangle

the media box of the page

getMetadataback to summary
public PDMetadata getMetadata()

Get the metadata that is part of the document catalog. This will return null if there is no meta data for this object.

Returns:PDMetadata

The metadata for this object.

getResourceCacheback to summary
public ResourceCache getResourceCache()

Returns the resource cache associated with this page, or null if there is none.

Returns:ResourceCache

the resource cache of the current page

getResourcesback to summary
public PDResources getResources()

Implements org.apache.pdfbox.contentstream.PDContentStream.getResources.

A dictionary containing any resources required by the page.

Returns:PDResources

Doc from org.apache.pdfbox.contentstream.PDContentStream.getResources.

the resources of the content stream or null

Annotations
@Override
getRotationback to summary
public int getRotation()

Returns the rotation angle in degrees by which the page should be rotated clockwise when displayed or printed. Valid values in a PDF must be a multiple of 90.

Returns:int

The rotation angle in degrees in normalized form (0, 90, 180 or 270) or 0 if invalid or not set at this level.

getStructParentsback to summary
public int getStructParents()

This will get the key of this Page in the structural parent tree.

Returns:int

the integer key of the page's entry in the structural parent tree or -1 if there isn't any.

getThreadBeadsback to summary
public List<PDThreadBead> getThreadBeads()

This will get a list of PDThreadBead objects, which are article threads in the document. This will return an empty list if there are no thread beads.

Returns:List<PDThreadBead>

A list of article threads on this page, never null. The returned list is backed by the beads COSArray, so any adding or deleting in this list will change the document too.

getTransitionback to summary
public PDTransition getTransition()
Returns:PDTransition

The page transition associated with this page or null if no transition is defined

getTrimBoxback to summary
public PDRectangle getTrimBox()

A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming. The default is the CropBox.

Returns:PDRectangle

The TrimBox attribute.

getUserUnitback to summary
public float getUserUnit()

Get the user unit. This is a positive number that shall give the size of default user space units, in multiples of 1/72 inch, or 1 if it hasn't been set. This is supported by PDF 1.6 and higher.

Returns:float

the user unit.

getViewportsback to summary
public List<PDViewportDictionary> getViewports()

Get the viewports.

Returns:List<PDViewportDictionary>

a list of viewports or null if there is no /VP entry.

hasContentsback to summary
public boolean hasContents()

Returns true if this page has one or more content streams.

Returns:boolean

true if the page has a non empty content stream, otherwise false

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
setActionsback to summary
public void setActions(PDPageAdditionalActions actions)

Set the page actions.

Parameters
actions:PDPageAdditionalActions

The actions for the page.

setAnnotationsback to summary
public void setAnnotations(List<PDAnnotation> annotations)

This will set the list of annotations. Although this is optional, you should take care that any newly created annotations link back to this page by calling PDAnnotation#setPage(org.apache.pdfbox.pdmodel.PDPage). Not doing it can cause trouble when PDFs get signed.

Parameters
annotations:List<PDAnnotation>

The new list of annotations.

setArtBoxback to summary
public void setArtBox(PDRectangle artBox)

This will set the ArtBox for this page.

Parameters
artBox:PDRectangle

The new ArtBox for this page.

setBleedBoxback to summary
public void setBleedBox(PDRectangle bleedBox)

This will set the BleedBox for this page.

Parameters
bleedBox:PDRectangle

The new BleedBox for this page.

setContentsback to summary
public void setContents(PDStream contents)

This will set the contents of this page.

Parameters
contents:PDStream

The new contents of the page.

setContentsback to summary
public void setContents(List<PDStream> contents)

This will set the contents of this page.

Parameters
contents:List<PDStream>

Array of new contents of the page.

setCropBoxback to summary
public void setCropBox(PDRectangle cropBox)

This will set the CropBox for this page.

Parameters
cropBox:PDRectangle

The new CropBox for this page.

setMediaBoxback to summary
public void setMediaBox(PDRectangle mediaBox)

This will set the mediaBox for this page.

Parameters
mediaBox:PDRectangle

The new mediaBox for this page.

setMetadataback to summary
public void setMetadata(PDMetadata meta)

Set the metadata for this object. This can be null.

Parameters
meta:PDMetadata

The meta data for this object.

setResourcesback to summary
public void setResources(PDResources resources)

This will set the resources for this page.

Parameters
resources:PDResources

The new resources for this page.

setRotationback to summary
public void setRotation(int rotation)

This will set the rotation for this page.

Parameters
rotation:int

The new rotation for this page in degrees.

setStructParentsback to summary
public void setStructParents(int structParents)

This will set the key for this page in the structural parent tree.

Parameters
structParents:int

The new key for this page.

setThreadBeadsback to summary
public void setThreadBeads(List<PDThreadBead> beads)

This will set the list of thread beads.

Parameters
beads:List<PDThreadBead>

A list of PDThreadBead objects or null.

setTransitionback to summary
public void setTransition(PDTransition transition)
Parameters
transition:PDTransition

The new transition to set on this page.

setTransitionback to summary
public void setTransition(PDTransition transition, float duration)

Convenient method to set a transition and the display duration

Parameters
transition:PDTransition

The new transition to set on this page.

duration:float

The maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.

setTrimBoxback to summary
public void setTrimBox(PDRectangle trimBox)

This will set the TrimBox for this page.

Parameters
trimBox:PDRectangle

The new TrimBox for this page.

setUserUnitback to summary
public void setUserUnit(float userUnit)

Get the user unit. This is a positive number that shall give the size of default user space units, in multiples of 1/72 inch. This is supported by PDF 1.6 and higher.

Parameters
userUnit:float

throws IllegalArgumentException if the parameter is not positive.

setViewportsback to summary
public void setViewports(List<PDViewportDictionary> viewports)

Set the viewports.

Parameters
viewports:List<PDViewportDictionary>

A list of viewports, or null if the entry is to be deleted.