Package org.apache.pdfbox.pdmodel
Class PDPage
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.PDPage
-
- All Implemented Interfaces:
java.awt.print.Printable
,COSObjectable
public class PDPage extends java.lang.Object implements COSObjectable, java.awt.print.Printable
This represents a single page in a PDF document.This class implements the
Printable
interface, but since PDFBox version 1.3.0 you should be using thePDPageable
adapter instead (see PDFBOX-788).- Version:
- $Revision: 1.29 $
- Author:
- Ben Litchfield
-
-
Field Summary
Fields Modifier and Type Field Description static PDRectangle
PAGE_SIZE_A0
A page size of A0 Paper.static PDRectangle
PAGE_SIZE_A1
A page size of A1 Paper.static PDRectangle
PAGE_SIZE_A2
A page size of A2 Paper.static PDRectangle
PAGE_SIZE_A3
A page size of A3 Paper.static PDRectangle
PAGE_SIZE_A4
A page size of A4 Paper.static PDRectangle
PAGE_SIZE_A5
A page size of A5 Paper.static PDRectangle
PAGE_SIZE_A6
A page size of A6 Paper.static PDRectangle
PAGE_SIZE_LETTER
A page size of LETTER or 8.5x11.
-
Constructor Summary
Constructors Constructor Description PDPage()
Creates a new instance of PDPage with a size of 8.5x11.PDPage(COSDictionary pageDic)
Creates a new instance of PDPage.PDPage(PDRectangle size)
Creates a new instance of PDPage.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clear()
Calling this will release all cached information.java.awt.image.BufferedImage
convertToImage()
Convert this page to an output image with 8 bits per pixel and the double default screen resolution.java.awt.image.BufferedImage
convertToImage(int imageType, int resolution)
Convert this page to an output image.boolean
equals(java.lang.Object other)
PDRectangle
findCropBox()
This will find the CropBox for this page by looking up the hierarchy until it finds them.PDRectangle
findMediaBox()
This will find the MediaBox for this page by looking up the hierarchy until it finds them.PDResources
findResources()
This will find the resources for this page by looking up the hierarchy until it finds them.int
findRotation()
This will find the rotation for this page by looking up the hierarchy until it finds them.PDPageAdditionalActions
getActions()
Get the page actions.java.util.List<PDAnnotation>
getAnnotations()
This will return a list of the annotations for this page.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 isthe CropBox.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.PDStream
getContents()
This will get the contents of the PDF Page, in the case that the contents of the page is an array then then the entire array of streams will be be wrapped and appear as a single stream.COSDictionary
getCOSDictionary()
This will get the underlying dictionary that this class acts on.COSBase
getCOSObject()
Convert this standard java object to a COS object.PDRectangle
getCropBox()
A rectangle, expressed in default user space units, defining the visible region of default user space.java.util.Calendar
getLastModified()
This will get the date that the content stream was last modified.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 This will get the MediaBox at this page and not look up the hierarchy.PDMetadata
getMetadata()
Get the metadata that is part of the document catalog.PDPageNode
getParent()
This is the parent page node.PDResources
getResources()
This will get the resources at this page and not look up the hierarchy.java.lang.Integer
getRotation()
A value representing the rotation.int
getStructParents()
This will get the key of this Page in the structural parent tree.java.util.List<PDThreadBead>
getThreadBeads()
This will get a list of PDThreadBead objects, which are article threads in the document.PDRectangle
getTrimBox()
A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming.int
hashCode()
int
print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
Deprecated.Use thePDPageable
adapter classvoid
setActions(PDPageAdditionalActions actions)
Set the page actions.void
setAnnotations(java.util.List<PDAnnotation> annots)
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(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 mediaBoxValue)
This will set the mediaBox for this page.void
setMetadata(PDMetadata meta)
Set the metadata for this object.void
setParent(PDPageNode parentNode)
This will set the parent of this page.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(java.util.List<PDThreadBead> beads)
This will set the list of thread beads.void
setTrimBox(PDRectangle trimBox)
This will set the TrimBox for this page.void
updateLastModified()
This will update the last modified time for the page object.
-
-
-
Field Detail
-
PAGE_SIZE_LETTER
public static final PDRectangle PAGE_SIZE_LETTER
A page size of LETTER or 8.5x11.
-
PAGE_SIZE_A0
public static final PDRectangle PAGE_SIZE_A0
A page size of A0 Paper.
-
PAGE_SIZE_A1
public static final PDRectangle PAGE_SIZE_A1
A page size of A1 Paper.
-
PAGE_SIZE_A2
public static final PDRectangle PAGE_SIZE_A2
A page size of A2 Paper.
-
PAGE_SIZE_A3
public static final PDRectangle PAGE_SIZE_A3
A page size of A3 Paper.
-
PAGE_SIZE_A4
public static final PDRectangle PAGE_SIZE_A4
A page size of A4 Paper.
-
PAGE_SIZE_A5
public static final PDRectangle PAGE_SIZE_A5
A page size of A5 Paper.
-
PAGE_SIZE_A6
public static final PDRectangle PAGE_SIZE_A6
A page size of A6 Paper.
-
-
Constructor Detail
-
PDPage
public PDPage()
Creates a new instance of PDPage with a size of 8.5x11.
-
PDPage
public PDPage(PDRectangle size)
Creates a new instance of PDPage.- Parameters:
size
- The MediaBox or the page.
-
PDPage
public PDPage(COSDictionary pageDic)
Creates a new instance of PDPage.- Parameters:
pageDic
- The existing page dictionary.
-
-
Method Detail
-
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.
-
getCOSDictionary
public COSDictionary getCOSDictionary()
This will get the underlying dictionary that this class acts on.- Returns:
- The underlying dictionary for this class.
-
getParent
public PDPageNode getParent()
This is the parent page node. The parent is a required element of the page. This will be null until this page is added to the document.- Returns:
- The parent to this page.
-
setParent
public void setParent(PDPageNode parentNode)
This will set the parent of this page.- Parameters:
parentNode
- The parent to this page node.
-
updateLastModified
public void updateLastModified()
This will update the last modified time for the page object.
-
getLastModified
public java.util.Calendar getLastModified() throws java.io.IOException
This will get the date that the content stream was last modified. This may return null.- Returns:
- The date the content stream was last modified.
- Throws:
java.io.IOException
- If there is an error accessing the date information.
-
getResources
public PDResources getResources()
This will get the resources at this page and not look up the hierarchy. This attribute is inheritable, and findResources() should probably used. This will return null if no resources are available at this level.- Returns:
- The resources at this level in the hierarchy.
-
findResources
public PDResources findResources()
This will find the resources for this page by looking up the hierarchy until it finds them.- Returns:
- The resources at this level in the hierarchy.
-
setResources
public void setResources(PDResources resources)
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
-
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.
-
getMediaBox
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 This will get the MediaBox at this page and not look up the hierarchy. This attribute is inheritable, and findMediaBox() should probably used. This will return null if no MediaBox are available at this level.- Returns:
- The MediaBox at this level in the hierarchy.
-
findMediaBox
public PDRectangle findMediaBox()
This will find the MediaBox for this page by looking up the hierarchy until it finds them.- Returns:
- The MediaBox at this level in the hierarchy.
-
setMediaBox
public void setMediaBox(PDRectangle mediaBoxValue)
This will set the mediaBox for this page.- Parameters:
mediaBoxValue
- The new mediaBox for this page.
-
getCropBox
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 and then imposed on the output medium in some implementationdefined manner This will get the CropBox at this page and not look up the hierarchy. This attribute is inheritable, and findCropBox() should probably used. This will return null if no CropBox is available at this level.- Returns:
- The CropBox at this level in the hierarchy.
-
findCropBox
public PDRectangle findCropBox()
This will find the CropBox for this page by looking up the hierarchy until it finds them.- Returns:
- The CropBox at this level in the hierarchy.
-
setCropBox
public void setCropBox(PDRectangle cropBox)
This will set the CropBox for this page.- Parameters:
cropBox
- The new CropBox for this page.
-
getBleedBox
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:
- The BleedBox attribute.
-
setBleedBox
public void setBleedBox(PDRectangle bleedBox)
This will set the BleedBox for this page.- Parameters:
bleedBox
- The new BleedBox for this page.
-
getTrimBox
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:
- The TrimBox attribute.
-
setTrimBox
public void setTrimBox(PDRectangle trimBox)
This will set the TrimBox for this page.- Parameters:
trimBox
- The new TrimBox for this page.
-
getArtBox
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 isthe CropBox.- Returns:
- The ArtBox attribute.
-
setArtBox
public void setArtBox(PDRectangle artBox)
This will set the ArtBox for this page.- Parameters:
artBox
- The new ArtBox for this page.
-
getRotation
public java.lang.Integer getRotation()
A value representing the rotation. This will be null if not set at this level The number of degrees by which the page should be rotated clockwise when displayed or printed. The value must be a multiple of 90. This will get the rotation at this page and not look up the hierarchy. This attribute is inheritable, and findRotation() should probably used. This will return null if no rotation is available at this level.- Returns:
- The rotation at this level in the hierarchy.
-
findRotation
public int findRotation()
This will find the rotation for this page by looking up the hierarchy until it finds them.- Returns:
- The rotation at this level in the hierarchy.
-
setRotation
public void setRotation(int rotation)
This will set the rotation for this page.- Parameters:
rotation
- The new rotation for this page in degrees.
-
getContents
public PDStream getContents() throws java.io.IOException
This will get the contents of the PDF Page, in the case that the contents of the page is an array then then the entire array of streams will be be wrapped and appear as a single stream.- Returns:
- The page content stream.
- Throws:
java.io.IOException
- If there is an error obtaining the stream.
-
setContents
public void setContents(PDStream contents)
This will set the contents of this page.- Parameters:
contents
- The new contents of the page.
-
getThreadBeads
public java.util.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:
- 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
public void setThreadBeads(java.util.List<PDThreadBead> beads)
This will set the list of thread beads.- Parameters:
beads
- A list of PDThreadBead objects or null.
-
getMetadata
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:
- The metadata for this object.
-
setMetadata
public void setMetadata(PDMetadata meta)
Set the metadata for this object. This can be null.- Parameters:
meta
- The meta data for this object.
-
convertToImage
public java.awt.image.BufferedImage convertToImage() throws java.io.IOException
Convert this page to an output image with 8 bits per pixel and the double default screen resolution.- Returns:
- A graphical representation of this page.
- Throws:
java.io.IOException
- If there is an error drawing to the image.
-
convertToImage
public java.awt.image.BufferedImage convertToImage(int imageType, int resolution) throws java.io.IOException
Convert this page to an output image.- Parameters:
imageType
- the image type (seeBufferedImage
.TYPE_*)resolution
- the resolution in dpi (dots per inch)- Returns:
- A graphical representation of this page.
- Throws:
java.io.IOException
- If there is an error drawing to the image.
-
getActions
public PDPageAdditionalActions getActions()
Get the page actions.- Returns:
- The Actions for this Page
-
setActions
public void setActions(PDPageAdditionalActions actions)
Set the page actions.- Parameters:
actions
- The actions for the page.
-
getAnnotations
public java.util.List<PDAnnotation> getAnnotations() throws java.io.IOException
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:
java.io.IOException
- If there is an error while creating the annotation list.
-
setAnnotations
public void setAnnotations(java.util.List<PDAnnotation> annots)
This will set the list of annotations.- Parameters:
annots
- The new list of annotations.
-
print
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException
Deprecated.Use thePDPageable
adapter class- Specified by:
print
in interfacejava.awt.print.Printable
- Throws:
java.awt.print.PrinterException
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
clear
public void clear()
Calling this will release all cached information.
-
-