Package org.apache.pdfbox.pdmodel
Class PDPage
java.lang.Object
org.apache.pdfbox.pdmodel.PDPage
- All Implemented Interfaces:
PDContentStream
,COSObjectable
A page in a PDF document.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.commons.logging.Log
Log instanceprivate PDRectangle
private final COSDictionary
private PDResources
private ResourceCache
-
Constructor Summary
ConstructorsConstructorDescriptionPDPage()
Creates a new PDPage instance for embedding, with a size of U.S.PDPage
(COSDictionary pageDictionary) Creates a new instance of PDPage for reading.PDPage
(COSDictionary pageDictionary, ResourceCache resourceCache) Creates a new instance of PDPage for reading.PDPage
(PDRectangle mediaBox) Creates a new instance of PDPage for embedding. -
Method Summary
Modifier and TypeMethodDescriptionprivate PDRectangle
Clips the given box to the bounds of the media box.boolean
Get the page actions.This will return a list of the annotations for this page.getAnnotations
(AnnotationFilter annotationFilter) This will return a list of the annotations for this page.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.getBBox()
Returns the bounding box of the contents.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.Returns the content stream(s) of this page as a single input stream.Returns the content streams which make up this page.Convert this standard java object to a COS object.A rectangle, expressed in default user space units, defining the visible region of default user space.Returns the matrix which transforms from the stream's space to user space.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.Get the metadata that is part of the document catalog.Returns the resource cache associated with this page, or null if there is none.A dictionary containing any resources required by the page.int
Returns the rotation angle in degrees by which the page should be rotated clockwise when displayed or printed.int
This will get the key of this Page in the structural parent tree.This will get a list of PDThreadBead objects, which are article threads in the document.A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming.float
Get the user unit.Get the viewports.boolean
Returns true if this page has one or more content streams.int
hashCode()
void
setActions
(PDPageAdditionalActions actions) Set the page actions.void
setAnnotations
(List<PDAnnotation> annotations) This will set the list of annotations.void
setArtBox
(PDRectangle artBox) This will set the ArtBox for this page.void
setBleedBox
(PDRectangle bleedBox) This will set the BleedBox for this page.void
setContents
(List<PDStream> contents) This will set the contents of this page.void
setContents
(PDStream contents) This will set the contents of this page.void
setCropBox
(PDRectangle cropBox) This will set the CropBox for this page.void
setMediaBox
(PDRectangle mediaBox) This will set the mediaBox for this page.void
setMetadata
(PDMetadata meta) Set the metadata for this object.void
setResources
(PDResources resources) This will set the resources for this page.void
setRotation
(int rotation) This will set the rotation for this page.void
setStructParents
(int structParents) This will set the key for this page in the structural parent tree.void
setThreadBeads
(List<PDThreadBead> beads) This will set the list of thread beads.void
setTransition
(PDTransition transition) void
setTransition
(PDTransition transition, float duration) Convenient method to set a transition and the display durationvoid
setTrimBox
(PDRectangle trimBox) This will set the TrimBox for this page.void
setUserUnit
(float userUnit) Get the user unit.void
setViewports
(List<PDViewportDictionary> viewports) Set the viewports.
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOGLog instance -
page
-
pageResources
-
resourceCache
-
mediaBox
-
-
Constructor Details
-
PDPage
public PDPage()Creates a new PDPage instance for embedding, with a size of U.S. Letter (8.5 x 11 inches). -
PDPage
Creates a new instance of PDPage for embedding.- Parameters:
mediaBox
- The MediaBox of the page.
-
PDPage
Creates a new instance of PDPage for reading.- Parameters:
pageDictionary
- A page dictionary in a PDF document.
-
PDPage
PDPage(COSDictionary pageDictionary, ResourceCache resourceCache) Creates a new instance of PDPage for reading.- Parameters:
pageDictionary
- A page dictionary in a PDF document.
-
-
Method Details
-
getCOSObject
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
getContentStreams
Returns the content streams which make up this page.- Returns:
- content stream iterator
-
getContents
Returns the content stream(s) of this page as a single input stream.- Specified by:
getContents
in interfacePDContentStream
- 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.
- Throws:
IOException
- If the stream could not be read
-
hasContents
public boolean hasContents()Returns true if this page has one or more content streams. -
getResources
A dictionary containing any resources required by the page.- Specified by:
getResources
in interfacePDContentStream
- Returns:
- the resources of this stream.
-
setResources
This will set the resources for this page.- Parameters:
resources
- The new resources for this page.
-
getStructParents
public int getStructParents()This will get the key of this Page in the structural parent tree.- Returns:
- the integer key of the page's entry in the structural parent tree or -1 if there isn't any.
-
setStructParents
public void setStructParents(int structParents) This will set the key for this page in the structural parent tree.- Parameters:
structParents
- The new key for this page.
-
getBBox
Description copied from interface:PDContentStream
Returns the bounding box of the contents.- Specified by:
getBBox
in interfacePDContentStream
- Returns:
- the bounding box of this stream.
-
getMatrix
Description copied from interface:PDContentStream
Returns the matrix which transforms from the stream's space to user space.- Specified by:
getMatrix
in interfacePDContentStream
- Returns:
- the matrix of this stream.
-
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:
- the media box.
-
setMediaBox
This will set the mediaBox for this page.- Parameters:
mediaBox
- The new mediaBox for this page.
-
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:
- the crop box.
-
setCropBox
This will set the CropBox for this page.- Parameters:
cropBox
- The new CropBox for this page.
-
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:
- The BleedBox attribute.
-
setBleedBox
This will set the BleedBox for this page.- Parameters:
bleedBox
- The new BleedBox for this page.
-
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:
- The TrimBox attribute.
-
setTrimBox
This will set the TrimBox for this page.- Parameters:
trimBox
- The new TrimBox for this page.
-
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:
- The ArtBox attribute.
-
setArtBox
This will set the ArtBox for this page.- Parameters:
artBox
- The new ArtBox for this page.
-
clipToMediaBox
Clips the given box to the bounds of the media box. -
getRotation
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:
- The rotation angle in degrees in normalized form (0, 90, 180 or 270) or 0 if invalid or not set at this level.
-
setRotation
public void setRotation(int rotation) This will set the rotation for this page.- Parameters:
rotation
- The new rotation for this page in degrees.
-
setContents
This will set the contents of this page.- Parameters:
contents
- The new contents of the page.
-
setContents
This will set the contents of this page.- Parameters:
contents
- Array of new contents of the page.
-
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:
- 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.
-
setThreadBeads
This will set the list of thread beads.- Parameters:
beads
- A list of PDThreadBead objects or null.
-
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:
- The metadata for this object.
-
setMetadata
Set the metadata for this object. This can be null.- Parameters:
meta
- The meta data for this object.
-
getActions
Get the page actions.- Returns:
- The Actions for this Page
-
setActions
Set the page actions.- Parameters:
actions
- The actions for the page.
-
getTransition
- Returns:
- The page transition associated with this page or null if no transition is defined
-
getAnnotations
This will return a list of the annotations for this page.- 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.
- Throws:
IOException
- If there is an error while creating the annotation list.
-
getAnnotations
This will return a list of the annotations for this page.- Parameters:
annotationFilter
- the annotation filter provided allowing to filter out specific annotations- 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.
- Throws:
IOException
- If there is an error while creating the annotation list.
-
setAnnotations
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 callingPDAnnotation.setPage(org.apache.pdfbox.pdmodel.PDPage)
. Not doing it can cause trouble when PDFs get signed.- Parameters:
annotations
- The new list of annotations.
-
equals
-
hashCode
public int hashCode() -
getResourceCache
Returns the resource cache associated with this page, or null if there is none.- Returns:
- the resource cache associated to this page.
-
getViewports
Get the viewports.- Returns:
- a list of viewports or null if there is no /VP entry.
-
setViewports
Set the viewports.- Parameters:
viewports
- A list of viewports, or null if the entry is to be deleted.
-
getUserUnit
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:
- the user unit.
-
setUserUnit
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
- throws IllegalArgumentException if the parameter is not positive.
-