com.sun.pdfview

Class PDFPage

public class PDFPage extends Object

A PDFPage encapsulates the parsed commands required to render a single page from a PDFFile. The PDFPage is not itself drawable; instead, create a PDFImage to display something on the screen.

This file also contains all of the PDFCmd commands that might be a part of the command stream in a PDFPage. They probably should be inner classes of PDFPage instead of separate non-public classes.

Constructor Summary
PDFPage(Rectangle2D bbox, int rotation)
create a PDFPage with dimensions in bbox and rotation.
PDFPage(int pageNumber, Rectangle2D bbox, int rotation, Cache cache)
create a PDFPage with dimensions in bbox and rotation.
Method Summary
voidaddCommand(PDFCmd cmd)
Add a single command to the page list.
voidaddCommands(PDFPage page)
add a collection of commands to the page list.
voidaddCommands(PDFPage page, AffineTransform extra)
add a collection of commands to the page list.
voidaddDash(float[] dashary, float phase)
set the dash style
voidaddEndCap(int capstyle)
set the end cap style
voidaddFillAlpha(float a)
set the fill alpha
voidaddFillPaint(PDFPaint p)
set the fill paint
voidaddImage(PDFImage image)
draw an image
voidaddLineJoin(int joinstyle)
set the line join style
voidaddMiterLimit(float limit)
set the miter limit
voidaddPath(GeneralPath path, int style)
set the current path
voidaddPop()
pop the graphics state
voidaddPush()
push the graphics state
voidaddStrokeAlpha(float a)
set the stroke alpha
voidaddStrokePaint(PDFPaint p)
set the stroke paint
voidaddStrokeWidth(float w)
set the stroke width
voidaddXform(AffineTransform at)
concatenate a transform to the graphics state
voidclearCommands()
Clear all commands off the current page
voidfinish()
The entire page is done.
floatgetAspectRatio()
get the aspect ratio of the correctly oriented page.
Rectangle2DgetBBox()
get the bounding box of the page, before any rotation.
PDFCmdgetCommand(int index)
get the command at a given index
intgetCommandCount()
get the current number of commands for this page
ListgetCommands()
get all the commands in the current page
ListgetCommands(int startIndex)
get all the commands in the current page starting at the given index
ListgetCommands(int startIndex, int endIndex)
floatgetHeight()
get the height of this page, after rotation
ImagegetImage(int width, int height, Rectangle2D clip, ImageObserver observer)
Get an image producer which can be used to draw the image represented by this PDFPage.
ImagegetImage(int width, int height, Rectangle2D clip, ImageObserver observer, boolean drawbg, boolean wait)
Get an image producer which can be used to draw the image represented by this PDFPage.
AffineTransformgetInitialTransform(int width, int height, Rectangle2D clip)
Get the initial transform to map from a specified clip rectangle in pdf coordinates to an image of the specfied width and height in device coordinates
intgetPageNumber()
get the page number used to lookup this page
intgetRotation()
get the rotation of this image
DimensiongetUnstretchedSize(int width, int height, Rectangle2D clip)
Get the width and height of this image in the correct aspect ratio.
floatgetWidth()
get the width of this page, after rotation
booleanisFinished()
get whether parsing for this PDFPage has been completed and all commands are in place.
voidstop(int width, int height, Rectangle2D clip)
Stop the rendering of a particular image on this page
voidupdateImages()
Notify all images we know about that a command has been added
voidwaitForFinish()
wait for finish

Constructor Detail

PDFPage

public PDFPage(Rectangle2D bbox, int rotation)
create a PDFPage with dimensions in bbox and rotation.

PDFPage

public PDFPage(int pageNumber, Rectangle2D bbox, int rotation, Cache cache)
create a PDFPage with dimensions in bbox and rotation.

Method Detail

addCommand

public void addCommand(PDFCmd cmd)
Add a single command to the page list.

addCommands

public void addCommands(PDFPage page)
add a collection of commands to the page list. This is probably invoked as the result of an XObject 'do' command, or through a type 3 font.

addCommands

public void addCommands(PDFPage page, AffineTransform extra)
add a collection of commands to the page list. This is probably invoked as the result of an XObject 'do' command, or through a type 3 font.

Parameters: page the source of other commands. It MUST be finished. extra a transform to perform before adding the commands. If null, no extra transform will be added.

addDash

public void addDash(float[] dashary, float phase)
set the dash style

Parameters: dashary the array of on-off lengths phase offset of the array at the start of the line drawing

addEndCap

public void addEndCap(int capstyle)
set the end cap style

Parameters: capstyle the cap style: 0 = BUTT, 1 = ROUND, 2 = SQUARE

addFillAlpha

public void addFillAlpha(float a)
set the fill alpha

addFillPaint

public void addFillPaint(PDFPaint p)
set the fill paint

addImage

public void addImage(PDFImage image)
draw an image

Parameters: image the image to draw

addLineJoin

public void addLineJoin(int joinstyle)
set the line join style

Parameters: joinstyle the join style: 0 = MITER, 1 = ROUND, 2 = BEVEL

addMiterLimit

public void addMiterLimit(float limit)
set the miter limit

addPath

public void addPath(GeneralPath path, int style)
set the current path

Parameters: path the path style the style: PDFShapeCmd.STROKE, PDFShapeCmd.FILL, PDFShapeCmd.BOTH, PDFShapeCmd.CLIP, or some combination.

addPop

public void addPop()
pop the graphics state

addPush

public void addPush()
push the graphics state

addStrokeAlpha

public void addStrokeAlpha(float a)
set the stroke alpha

addStrokePaint

public void addStrokePaint(PDFPaint p)
set the stroke paint

addStrokeWidth

public void addStrokeWidth(float w)
set the stroke width

Parameters: w the width of the stroke

addXform

public void addXform(AffineTransform at)
concatenate a transform to the graphics state

clearCommands

public void clearCommands()
Clear all commands off the current page

finish

public void finish()
The entire page is done. This must only be invoked once. All observers will be notified.

getAspectRatio

public float getAspectRatio()
get the aspect ratio of the correctly oriented page.

Returns: the width/height aspect ratio of the page

getBBox

public Rectangle2D getBBox()
get the bounding box of the page, before any rotation.

getCommand

public PDFCmd getCommand(int index)
get the command at a given index

getCommandCount

public int getCommandCount()
get the current number of commands for this page

getCommands

public List getCommands()
get all the commands in the current page

getCommands

public List getCommands(int startIndex)
get all the commands in the current page starting at the given index

getCommands

public List getCommands(int startIndex, int endIndex)

getHeight

public float getHeight()
get the height of this page, after rotation

getImage

public Image getImage(int width, int height, Rectangle2D clip, ImageObserver observer)
Get an image producer which can be used to draw the image represented by this PDFPage. The ImageProducer is guaranteed to stay in sync with the PDFPage as commands are added to it. The image will contain the section of the page specified by the clip, scaled to fit in the area given by width and height.

Parameters: width the width of the image to be produced height the height of the image to be produced clip the region in page space of the entire page to display observer an image observer who will be notified when the image changes, or null

Returns: an Image that contains the PDF data

getImage

public Image getImage(int width, int height, Rectangle2D clip, ImageObserver observer, boolean drawbg, boolean wait)
Get an image producer which can be used to draw the image represented by this PDFPage. The ImageProducer is guaranteed to stay in sync with the PDFPage as commands are added to it. The image will contain the section of the page specified by the clip, scaled to fit in the area given by width and height.

Parameters: width the width of the image to be produced height the height of the image to be produced clip the region in page space of the entire page to display observer an image observer who will be notified when the image changes, or null drawbg if true, put a white background on the image. If not, draw no color (alpha 0) for the background. wait if true, do not return until this image is fully rendered.

Returns: an Image that contains the PDF data

getInitialTransform

public AffineTransform getInitialTransform(int width, int height, Rectangle2D clip)
Get the initial transform to map from a specified clip rectangle in pdf coordinates to an image of the specfied width and height in device coordinates

Parameters: width the width of the image height the height of the image clip the desired clip rectangle (in PDF space) or null to use the page's bounding box

getPageNumber

public int getPageNumber()
get the page number used to lookup this page

Returns: the page number

getRotation

public int getRotation()
get the rotation of this image

getUnstretchedSize

public Dimension getUnstretchedSize(int width, int height, Rectangle2D clip)
Get the width and height of this image in the correct aspect ratio. The image returned will have at least one of the width and height values identical to those requested. The other dimension may be smaller, so as to keep the aspect ratio the same as in the original page.

Parameters: width the maximum width of the image height the maximum height of the image clip the region in page space of the page to display. It may be null, in which the page's defined crop box will be used.

getWidth

public float getWidth()
get the width of this page, after rotation

isFinished

public boolean isFinished()
get whether parsing for this PDFPage has been completed and all commands are in place.

stop

public void stop(int width, int height, Rectangle2D clip)
Stop the rendering of a particular image on this page

updateImages

public void updateImages()
Notify all images we know about that a command has been added

waitForFinish

public void waitForFinish()
wait for finish