Class PDPage

java.lang.Object
org.apache.pdfbox.pdmodel.PDPage
All Implemented Interfaces:
PDContentStream, COSObjectable

public class PDPage extends Object implements COSObjectable, PDContentStream
A page in a PDF document.
Author:
Ben Litchfield
  • 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

      public PDPage(PDRectangle mediaBox)
      Creates a new instance of PDPage for embedding.
      Parameters:
      mediaBox - The MediaBox of the page.
    • PDPage

      public PDPage(COSDictionary pageDictionary)
      Creates a new instance of PDPage for reading.
      Parameters:
      pageDictionary - A page dictionary in a PDF document.
  • Method Details

    • getCOSObject

      public COSDictionary getCOSObject()
      Convert this standard java object to a COS object.
      Specified by:
      getCOSObject in interface COSObjectable
      Returns:
      The cos object that matches this Java object.
    • getContentStreams

      public Iterator<PDStream> getContentStreams()
      Returns the content streams which make up this page.
      Returns:
      content stream iterator
    • getContents

      public InputStream getContents() throws IOException
      Returns the content stream(s) of this page as a single input stream.
      Specified by:
      getContents in interface PDContentStream
      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

      public PDResources getResources()
      A dictionary containing any resources required by the page.
      Specified by:
      getResources in interface PDContentStream
      Returns:
      the resources of this stream.
    • 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 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

      public PDRectangle getBBox()
      Description copied from interface: PDContentStream
      Returns the bounding box of the contents.
      Specified by:
      getBBox in interface PDContentStream
      Returns:
      the bounding box of this stream.
    • getMatrix

      public Matrix getMatrix()
      Description copied from interface: PDContentStream
      Returns the matrix which transforms from the stream's space to user space.
      Specified by:
      getMatrix in interface PDContentStream
      Returns:
      the matrix of this stream.
    • 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.
      Returns:
      the media box.
    • setMediaBox

      public void setMediaBox(PDRectangle mediaBox)
      This will set the mediaBox for this page.
      Parameters:
      mediaBox - 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.
      Returns:
      the crop box.
    • 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 is the 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 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

      public void setContents(PDStream contents)
      This will set the contents of this page.
      Parameters:
      contents - The new contents of the page.
    • setContents

      public void setContents(List<PDStream> contents)
      This will set the contents of this page.
      Parameters:
      contents - Array of new contents of the page.
    • getThreadBeads

      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:
      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(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.
    • 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.
    • getTransition

      public PDTransition getTransition()
      Returns:
      The page transition associated with this page or null if no transition is defined
    • setTransition

      public void setTransition(PDTransition transition)
      Parameters:
      transition - The new transition to set on this page.
    • setTransition

      public void setTransition(PDTransition transition, float duration)
      Convenient method to set a transition and the display duration
      Parameters:
      transition - The new transition to set on this page.
      duration - 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.
    • getAnnotations

      public List<PDAnnotation> getAnnotations() throws 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:
      IOException - If there is an error while creating the annotation list.
    • getAnnotations

      public List<PDAnnotation> getAnnotations(AnnotationFilter annotationFilter) throws IOException
      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

      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 - The new list of annotations.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getResourceCache

      public ResourceCache getResourceCache()
      Returns the resource cache associated with this page, or null if there is none.
      Returns:
      the resource cache associated to this page.
    • getViewports

      public List<PDViewportDictionary> getViewports()
      Get the viewports.
      Returns:
      a list of viewports or null if there is no /VP entry.
    • setViewports

      public void setViewports(List<PDViewportDictionary> viewports)
      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.