Package pdf

Class PDFPage

  • All Implemented Interfaces:
    java.io.Serializable

    public class PDFPage
    extends PDFObject
    implements java.io.Serializable

    This class defines a single page within a document. It is linked to a single PDFGraphics object

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  PDFPage.procset
      This defines a procset
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Vector<PDFObject> annotations
      This holds any Annotations contained within this page.
      protected java.util.Vector<PDFObject> contents
      This holds the contents of the page.
      protected java.util.Vector<PDFFont> fonts
      The fonts associated with this page
      protected boolean hasImageB
      These handle the procset for this page.
      protected boolean hasImageC
      These handle the procset for this page.
      protected boolean hasImageI
      These handle the procset for this page.
      protected java.util.Vector<java.lang.String> imageResources  
      protected java.awt.print.PageFormat pageFormat
      This is this page format, ie the size of the page, margins, and rotation
      protected PDFObject pdfPageList
      This is the pages object id that this page belongs to.
      protected PDFPage.procset procset  
      protected java.util.Vector<java.lang.String> resources
      This holds any resources for this page
      protected PDFObject thumbnail
      Object ID that contains a thumbnail sketch of the page
    • Constructor Summary

      Constructors 
      Constructor Description
      PDFPage()
      This constructs a Page object, which will hold any contents for this page.
      PDFPage​(int orientation)
      Constructs a page using A4 media, but using the supplied orientation.
      PDFPage​(java.awt.print.PageFormat pageFormat)
      Constructs a page using the supplied media size and orientation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(PDFObject ob)
      This adds an object that describes some content to this page.
      void addAnnotation​(PDFObject ob)
      This adds an Annotation to the page.
      void addImageResource​(java.lang.String resource)
      This adds an image resource to the page.
      PDFAnnot addLink​(int x, int y, int w, int h, PDFObject dest)
      Adds a hyperlink to the document.
      PDFAnnot addLink​(int x, int y, int w, int h, PDFObject dest, int vx, int vy, int vw, int vh)
      Adds a hyperlink to the document.
      PDFAnnot addNote​(java.lang.String note, int x, int y, int w, int h)
      This method adds a text note to the document.
      PDFOutline addOutline​(java.lang.String title)
      This method attaches an outline to the current page being generated.
      PDFOutline addOutline​(java.lang.String title, int x, int y, int w, int h)
      This method attaches an outline to the current page being generated.
      void addResource​(java.lang.String resource)
      This adds a resource to the page.
      void addToProcset​(java.lang.String proc)
      Adds to procset.
      void addXObject​(java.lang.String inxobject)
      This adds an XObject resource to the page.
      int cx​(int x, int y)
      This utility method converts the y coordinate from Java to User space within the page.
      int[] cxy​(int x, int y)
      This utility method converts the Java coordinates to User space within the page.
      int cy​(int x, int y)
      This utility method converts the y coordinate from Java to User space within the page.
      java.awt.Dimension getDimension()
      Gets the dimensions of the page.
      PDFFont getFont​(java.lang.String type, java.lang.String font, int style)
      Returns a PDFFont, creating it if not yet used.
      PDFGraphics getGraphics()
      This returns a PDFGraphics object, which can then be used to render on to this page.
      java.awt.Rectangle getImageableArea()
      Gets the imageable area of the page.
      int getOrientation()
      Returns the pages orientation: PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE
      java.awt.print.PageFormat getPageFormat()
      Returns the page's PageFormat.
      void setOrientation​(int orientation)
      Sets the page's orientation.
      void setThumbnail​(PDFObject thumbnail)
      This adds an object that describes a thumbnail for this page.
      void write​(java.io.OutputStream os)
      Writes the object to the output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • pageFormat

        protected java.awt.print.PageFormat pageFormat
        This is this page format, ie the size of the page, margins, and rotation
      • pdfPageList

        protected PDFObject pdfPageList
        This is the pages object id that this page belongs to. It is set by the pages object when it is added to it.
      • contents

        protected java.util.Vector<PDFObject> contents
        This holds the contents of the page.
      • thumbnail

        protected PDFObject thumbnail
        Object ID that contains a thumbnail sketch of the page. -1 indicates no thumbnail.
      • annotations

        protected java.util.Vector<PDFObject> annotations
        This holds any Annotations contained within this page.
      • resources

        protected java.util.Vector<java.lang.String> resources
        This holds any resources for this page
      • imageResources

        protected java.util.Vector<java.lang.String> imageResources
      • fonts

        protected java.util.Vector<PDFFont> fonts
        The fonts associated with this page
      • hasImageB

        protected boolean hasImageB
        These handle the procset for this page. Refer to page 140 of the PDF Reference manual NB: Text is handled when the fonts Vector is null, and a font is created refer to getFont() to see where it's defined
      • hasImageC

        protected boolean hasImageC
        These handle the procset for this page. Refer to page 140 of the PDF Reference manual NB: Text is handled when the fonts Vector is null, and a font is created refer to getFont() to see where it's defined
      • hasImageI

        protected boolean hasImageI
        These handle the procset for this page. Refer to page 140 of the PDF Reference manual NB: Text is handled when the fonts Vector is null, and a font is created refer to getFont() to see where it's defined
    • Constructor Detail

      • PDFPage

        public PDFPage()
        This constructs a Page object, which will hold any contents for this page.

        Once created, it is added to the document via the PDF.add() method. (For Advanced use, via the PDFPages.add() method).

        This defaults to a4 media.

      • PDFPage

        public PDFPage​(int orientation)
        Constructs a page using A4 media, but using the supplied orientation.
        Parameters:
        orientation - Orientation: 0, 90 or 270
        See Also:
        PageFormat.PORTRAIT, PageFormat.LANDSCAPE, PageFormat.REVERSE_LANDSCAPE
      • PDFPage

        public PDFPage​(java.awt.print.PageFormat pageFormat)
        Constructs a page using the supplied media size and orientation.
        Parameters:
        pageFormat - PageFormat describing the page size
    • Method Detail

      • addToProcset

        public void addToProcset​(java.lang.String proc)
        Adds to procset.
        Parameters:
        proc - the String to be added.
      • getGraphics

        public PDFGraphics getGraphics()
        This returns a PDFGraphics object, which can then be used to render on to this page. If a previous PDFGraphics object was used, this object is appended to the page, and will be drawn over the top of any previous objects.
        Returns:
        a new PDFGraphics object to be used to draw this page.
      • getFont

        public PDFFont getFont​(java.lang.String type,
                               java.lang.String font,
                               int style)
        Returns a PDFFont, creating it if not yet used.
        Parameters:
        type - Font type, usually /Type1
        font - Font name
        style - java.awt.Font style, ie Font.NORMAL
        Returns:
        a PDFFont object.
      • getPageFormat

        public java.awt.print.PageFormat getPageFormat()
        Returns the page's PageFormat.
        Returns:
        PageFormat describing the page size in device units (72dpi)
      • getDimension

        public java.awt.Dimension getDimension()
        Gets the dimensions of the page.
        Returns:
        a Dimension object containing the width and height of the page.
      • getImageableArea

        public java.awt.Rectangle getImageableArea()
        Gets the imageable area of the page.
        Returns:
        a Rectangle containing the bounds of the imageable area.
      • setOrientation

        public void setOrientation​(int orientation)
        Sets the page's orientation.

        Normally, this should be done when the page is created, to avoid problems.

        Parameters:
        orientation - a PageFormat orientation constant: PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE
      • getOrientation

        public int getOrientation()
        Returns the pages orientation: PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE
        Returns:
        current orientation of the page
        See Also:
        PageFormat
      • add

        public void add​(PDFObject ob)
        This adds an object that describes some content to this page.

        Note: Objects that describe contents must be added using this method _AFTER_ the PDF.add() method has been called.

        Parameters:
        ob - PDFObject describing some contents
      • addAnnotation

        public void addAnnotation​(PDFObject ob)
        This adds an Annotation to the page.

        As with other objects, the annotation must be added to the pdf document using PDF.add() before adding to the page.

        Parameters:
        ob - Annotation to add.
      • addNote

        public PDFAnnot addNote​(java.lang.String note,
                                int x,
                                int y,
                                int w,
                                int h)
        This method adds a text note to the document.
        Parameters:
        note - Text of the note
        x - Coordinate of note
        y - Coordinate of note
        w - Width of the note
        h - Height of the note
        Returns:
        Returns the annotation, so other settings can be changed.
      • addLink

        public PDFAnnot addLink​(int x,
                                int y,
                                int w,
                                int h,
                                PDFObject dest)
        Adds a hyperlink to the document.
        Parameters:
        x - Coordinate of active area
        y - Coordinate of active area
        w - Width of the active area
        h - Height of the active area
        dest - Page that will be displayed when the link is activated. When displayed, the zoom factor will be changed to fit the display.
        Returns:
        Returns the annotation, so other settings can be changed.
      • addLink

        public PDFAnnot addLink​(int x,
                                int y,
                                int w,
                                int h,
                                PDFObject dest,
                                int vx,
                                int vy,
                                int vw,
                                int vh)
        Adds a hyperlink to the document.
        Parameters:
        x - Coordinate of active area
        y - Coordinate of active area
        w - Width of the active area
        h - Height of the active area
        dest - Page that will be displayed when the link is activated
        vx - Coordinate of view area
        vy - Coordinate of view area
        vw - Width of the view area
        vh - Height of the view area
        Returns:
        Returns the annotation, so other settings can be changed.
      • addXObject

        public void addXObject​(java.lang.String inxobject)
        This adds an XObject resource to the page. The string should be of the format /Name ObjectNumber RevisionNumber R as in /Image1 13 0 R .
        Parameters:
        inxobject - the XObject resource to be added.
      • addResource

        public void addResource​(java.lang.String resource)
        This adds a resource to the page.
        Parameters:
        resource - String defining the resource
      • addImageResource

        public void addImageResource​(java.lang.String resource)
        This adds an image resource to the page.
        Parameters:
        resource - the XObject resource to be added.
      • setThumbnail

        public void setThumbnail​(PDFObject thumbnail)
        This adds an object that describes a thumbnail for this page.

        Note: The object must already exist in the PDF, as only the object ID is stored.

        Parameters:
        thumbnail - PDFObject containing the thumbnail
      • addOutline

        public PDFOutline addOutline​(java.lang.String title)
        This method attaches an outline to the current page being generated. When selected, the outline displays the top of the page.
        Parameters:
        title - Outline title to attach
        Returns:
        PDFOutline object created, for addSubOutline if required.
      • addOutline

        public PDFOutline addOutline​(java.lang.String title,
                                     int x,
                                     int y,
                                     int w,
                                     int h)
        This method attaches an outline to the current page being generated. When selected, the outline displays the top of the page.

        Note: If the outline is not in the top level (ie below another outline) then it must not be passed to this method.

        Parameters:
        title - Outline title to attach
        x - Left coordinate of region
        y - Bottom coordinate of region
        w - Width of region
        h - Height coordinate of region
        Returns:
        PDFOutline object created, for addSubOutline if required.
      • write

        public void write​(java.io.OutputStream os)
                   throws java.io.IOException
        Description copied from class: PDFObject

        Writes the object to the output stream. This method must be overidden.

        Note: It should not write any other objects, even if they are it's Kids, as they will be written by the calling routine.

        Specified by:
        write in class PDFObject
        Parameters:
        os - OutputStream to send the object to
        Throws:
        java.io.IOException - on error
      • cy

        public int cy​(int x,
                      int y)
        This utility method converts the y coordinate from Java to User space within the page.
        Parameters:
        x - Coordinate in Java space
        y - Coordinate in Java space
        Returns:
        y Coordinate in User space
      • cx

        public int cx​(int x,
                      int y)
        This utility method converts the y coordinate from Java to User space within the page.
        Parameters:
        x - Coordinate in Java space
        y - Coordinate in Java space
        Returns:
        x Coordinate in User space
      • cxy

        public int[] cxy​(int x,
                         int y)
        This utility method converts the Java coordinates to User space within the page.
        Parameters:
        x - Coordinate in Java space
        y - Coordinate in Java space
        Returns:
        array containing the x and y Coordinate in User space