gnu.jpdf
Class PDFPage

java.lang.Object
  extended by gnu.jpdf.PDFObject
      extended by gnu.jpdf.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
 class PDFPage.procset
          This defines a procset
 
Field Summary
protected  java.util.Vector annotations
          This holds any Annotations contained within this page.
protected  java.util.Vector contents
          This holds the contents of the page.
protected  java.util.Vector 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 imageResources
           
static int INVERTEDPORTRAIT
          Specifies that the page is in INVERTEDPORTRAIT orientation.
static int LANDSCAPE
          Specifies that the page is in LANDSCAPE orientation.
static java.awt.Rectangle MEDIA_11x17
          Rectangle defining a page in 11x17 format.
static java.awt.Rectangle MEDIA_a0
          Rectangle defining a page in a0 format.
static java.awt.Rectangle MEDIA_a1
          Rectangle defining a page in a1 format.
static java.awt.Rectangle MEDIA_a10
          Rectangle defining a page in a10 format.
static java.awt.Rectangle MEDIA_a2
          Rectangle defining a page in a2 format.
static java.awt.Rectangle MEDIA_a3
          Rectangle defining a page in a3 format.
static java.awt.Rectangle MEDIA_a4
          Rectangle defining a page in a4 format.
static java.awt.Rectangle MEDIA_a5
          Rectangle defining a page in a5 format.
static java.awt.Rectangle MEDIA_a6
          Rectangle defining a page in a6 format.
static java.awt.Rectangle MEDIA_a7
          Rectangle defining a page in a7 format.
static java.awt.Rectangle MEDIA_a8
          Rectangle defining a page in a8 format.
static java.awt.Rectangle MEDIA_a9
          Rectangle defining a page in a9 format.
static java.awt.Rectangle MEDIA_archA
          Rectangle defining a page in archA format.
static java.awt.Rectangle MEDIA_archB
          Rectangle defining a page in archB format.
static java.awt.Rectangle MEDIA_archC
          Rectangle defining a page in archC format.
static java.awt.Rectangle MEDIA_archD
          Rectangle defining a page in archD format.
static java.awt.Rectangle MEDIA_archE
          Rectangle defining a page in archE format.
static java.awt.Rectangle MEDIA_b0
          Rectangle defining a page in b0 format.
static java.awt.Rectangle MEDIA_b1
          Rectangle defining a page in b1 format.
static java.awt.Rectangle MEDIA_b2
          Rectangle defining a page in b2 format.
static java.awt.Rectangle MEDIA_b3
          Rectangle defining a page in b3 format.
static java.awt.Rectangle MEDIA_b4
          Rectangle defining a page in b4 format.
static java.awt.Rectangle MEDIA_b5
          Rectangle defining a page in b5 format.
static java.awt.Rectangle MEDIA_flsa
          Rectangle defining a page in flsa format.
static java.awt.Rectangle MEDIA_flse
          Rectangle defining a page in flse format.
static java.awt.Rectangle MEDIA_halfletter
          Rectangle defining a page in halfletter format.
static java.awt.Rectangle MEDIA_ledger
          Rectangle defining a page in ledger format.
static java.awt.Rectangle MEDIA_legal
          Rectangle defining a page in legal format.
static java.awt.Rectangle MEDIA_letter
          Rectangle defining a page in letter format.
static java.awt.Rectangle MEDIA_note
          Rectangle defining a page in note format.
protected  java.awt.Rectangle mediabox
          This is this pages media box, ie the size of the page
protected  PDFObject pdfPageList
          This is the pages object id that this page belongs to.
static int PORTRAIT
          Specifies that the page is in PORTRAIT orientation.
protected  PDFPage.procset procset
           
protected  java.util.Vector resources
          This holds any resources for this page
protected  int rotate
          Specifies the number of degrees the page should be rotated clockwise when it is displayed.
static int SEASCAPE
          Specifies that the page is in SEASCAPE orientation.
protected  PDFObject thumbnail
          Object ID that contains a thumbnail sketch of the page.
 
Fields inherited from class gnu.jpdf.PDFObject
objser, pdfDocument
 
Constructor Summary
PDFPage()
          This constructs a Page object, which will hold any contents for this page.
PDFPage(int rotate)
          Constructs a page using A4 media, but using the supplied orientation.
PDFPage(java.awt.Rectangle mediabox)
          Constructs a page, using the supplied media size.
PDFPage(java.awt.Rectangle mediabox, int rotate)
          Constructs a page using the supplied media size and orientation.
 
Method Summary
 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)
           
 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)
           
 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()
           
 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 getMedia()
          Returns the page's media.
 int getOrientation()
          Returns the pages orientation
 void setMedia(java.awt.Rectangle mediabox)
          Sets the media size for this page.
 void setOrientation(int rotate)
          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 gnu.jpdf.PDFObject
getPDFDocument, getSerialID, getType, toArray, toString, writeEnd, writeStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PORTRAIT

public static final int PORTRAIT
Specifies that the page is in PORTRAIT orientation.

See Also:
Constant Field Values

LANDSCAPE

public static final int LANDSCAPE
Specifies that the page is in LANDSCAPE orientation.

See Also:
Constant Field Values

INVERTEDPORTRAIT

public static final int INVERTEDPORTRAIT
Specifies that the page is in INVERTEDPORTRAIT orientation.

See Also:
Constant Field Values

SEASCAPE

public static final int SEASCAPE
Specifies that the page is in SEASCAPE orientation.

See Also:
Constant Field Values

MEDIA_letter

public static final java.awt.Rectangle MEDIA_letter
Rectangle defining a page in letter format.


MEDIA_note

public static final java.awt.Rectangle MEDIA_note
Rectangle defining a page in note format.


MEDIA_legal

public static final java.awt.Rectangle MEDIA_legal
Rectangle defining a page in legal format.


MEDIA_a0

public static final java.awt.Rectangle MEDIA_a0
Rectangle defining a page in a0 format.


MEDIA_a1

public static final java.awt.Rectangle MEDIA_a1
Rectangle defining a page in a1 format.


MEDIA_a2

public static final java.awt.Rectangle MEDIA_a2
Rectangle defining a page in a2 format.


MEDIA_a3

public static final java.awt.Rectangle MEDIA_a3
Rectangle defining a page in a3 format.


MEDIA_a4

public static final java.awt.Rectangle MEDIA_a4
Rectangle defining a page in a4 format.


MEDIA_a5

public static final java.awt.Rectangle MEDIA_a5
Rectangle defining a page in a5 format.


MEDIA_a6

public static final java.awt.Rectangle MEDIA_a6
Rectangle defining a page in a6 format.


MEDIA_a7

public static final java.awt.Rectangle MEDIA_a7
Rectangle defining a page in a7 format.


MEDIA_a8

public static final java.awt.Rectangle MEDIA_a8
Rectangle defining a page in a8 format.


MEDIA_a9

public static final java.awt.Rectangle MEDIA_a9
Rectangle defining a page in a9 format.


MEDIA_a10

public static final java.awt.Rectangle MEDIA_a10
Rectangle defining a page in a10 format.


MEDIA_b0

public static final java.awt.Rectangle MEDIA_b0
Rectangle defining a page in b0 format.


MEDIA_b1

public static final java.awt.Rectangle MEDIA_b1
Rectangle defining a page in b1 format.


MEDIA_b2

public static final java.awt.Rectangle MEDIA_b2
Rectangle defining a page in b2 format.


MEDIA_b3

public static final java.awt.Rectangle MEDIA_b3
Rectangle defining a page in b3 format.


MEDIA_b4

public static final java.awt.Rectangle MEDIA_b4
Rectangle defining a page in b4 format.


MEDIA_b5

public static final java.awt.Rectangle MEDIA_b5
Rectangle defining a page in b5 format.


MEDIA_archE

public static final java.awt.Rectangle MEDIA_archE
Rectangle defining a page in archE format.


MEDIA_archD

public static final java.awt.Rectangle MEDIA_archD
Rectangle defining a page in archD format.


MEDIA_archC

public static final java.awt.Rectangle MEDIA_archC
Rectangle defining a page in archC format.


MEDIA_archB

public static final java.awt.Rectangle MEDIA_archB
Rectangle defining a page in archB format.


MEDIA_archA

public static final java.awt.Rectangle MEDIA_archA
Rectangle defining a page in archA format.


MEDIA_flsa

public static final java.awt.Rectangle MEDIA_flsa
Rectangle defining a page in flsa format.


MEDIA_flse

public static final java.awt.Rectangle MEDIA_flse
Rectangle defining a page in flse format.


MEDIA_halfletter

public static final java.awt.Rectangle MEDIA_halfletter
Rectangle defining a page in halfletter format.


MEDIA_11x17

public static final java.awt.Rectangle MEDIA_11x17
Rectangle defining a page in 11x17 format.


MEDIA_ledger

public static final java.awt.Rectangle MEDIA_ledger
Rectangle defining a page in ledger format.


mediabox

protected java.awt.Rectangle mediabox
This is this pages media box, ie the size of the page


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 contents
This holds the contents of the page.


rotate

protected int rotate
Specifies the number of degrees the page should be rotated clockwise when it is displayed. This value must be zero (the default), or a multiple of 90.

See Also:
PORTRAIT, LANDSCAPE, INVERTEDPORTRAIT, SEASCAPE

thumbnail

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


annotations

protected java.util.Vector annotations
This holds any Annotations contained within this page.


resources

protected java.util.Vector resources
This holds any resources for this page


imageResources

protected java.util.Vector imageResources

fonts

protected java.util.Vector 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


procset

protected PDFPage.procset procset
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(java.awt.Rectangle mediabox)
Constructs a page, using the supplied media size.

Parameters:
mediabox - Rectangle describing the page size

PDFPage

public PDFPage(int rotate)
Constructs a page using A4 media, but using the supplied orientation.

Parameters:
rotate - Rotation: 0, 90, 180 or 270
See Also:
PORTRAIT, LANDSCAPE, INVERTEDPORTRAIT, SEASCAPE

PDFPage

public PDFPage(java.awt.Rectangle mediabox,
               int rotate)
Constructs a page using the supplied media size and orientation.

Parameters:
mediabox - Rectangle describing the page size
rotate - Rotation: 0, 90, 180 or 270
See Also:
PORTRAIT, LANDSCAPE, INVERTEDPORTRAIT, SEASCAPE
Method Detail

addToProcset

public void addToProcset(java.lang.String proc)

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.


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

setMedia

public void setMedia(java.awt.Rectangle mediabox)
Sets the media size for this page.

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

Parameters:
mediabox - Rectangle describing the page size

getMedia

public java.awt.Rectangle getMedia()
Returns the page's media.

Returns:
Rectangle describing the page size in device units (72dpi)

getDimension

public java.awt.Dimension getDimension()

setOrientation

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

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

Parameters:
rotate - Rotation: 0, 90, 180 or 270

getOrientation

public int getOrientation()
Returns the pages orientation

Returns:
current rotation of the page
See Also:
PORTRAIT, LANDSCAPE, INVERTEDPORTRAIT, SEASCAPE

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 what part of the page should be displayed
vy - Coordinate of what part of the page should be displayed
vw - Width of the what part of the page should be displayed
vh - Height of the what part of the page should be displayed (defined in Java coordinates). If this is null, then the page is fitted to the display.
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 .


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)

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 - int coordinate of region
y - int coordinate of region
w - int coordinate of region
h - int 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:
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:
y - Coordinate in Java space
Returns:
y 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 & y Coordinate in User space