Package org.loboevolution.pdfview
Class PDFPage
java.lang.Object
org.loboevolution.pdfview.PDFPage
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.
Author Mike Wessler
-
Field Summary
Modifier and TypeFieldDescriptionfinal Map
<ImageInfo, WeakReference<?>> a map from image info to weak references to parsers that are active -
Constructor Summary
ConstructorDescriptionPDFPage
(int pageNumber, Rectangle2D bbox, int rote, Cache cache) create a PDFPage with dimensions in bbox and rotation.PDFPage
(Rectangle2D bbox, int rotation) create a PDFPage with dimensions in bbox and rotation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnnotations.void
addCommand
(PDFCmd cmd) Add a single command to the page list.void
addCommands
(PDFPage page) add a collection of commands to the page list.void
addCommands
(PDFPage page, AffineTransform extra) add a collection of commands to the page list.void
addDash
(float[] dashary, float phase) set the dash stylevoid
addEndCap
(int capstyle) set the end cap stylevoid
addFillAlpha
(float a) set the fill alphavoid
set the fill paintvoid
draw an imagevoid
addLineJoin
(int joinstyle) set the line join stylevoid
addMiterLimit
(float limit) set the miter limitvoid
addPath
(GeneralPath path, int style, boolean autoAdjustStroke) set the current pathvoid
addPop()
pop the graphics statevoid
addPush()
push the graphics statevoid
addShadeCommand
(PDFPaint p, Rectangle2D box) addShadeCommand.void
addStrokeAlpha
(float a) set the stroke alphavoid
set the stroke paintorg.loboevolution.pdfview.PDFChangeStrokeCmd
addStrokeWidth
(float w) set the stroke widthvoid
concatenate a transform to the graphics statevoid
Clear all commands off the current pagestatic org.loboevolution.pdfview.PDFImageCmd
createImageCmd
(PDFImage image) createImageCmd.static org.loboevolution.pdfview.PDFPopCmd
createPopCmd.static org.loboevolution.pdfview.PDFPushCmd
createPushCmd.static org.loboevolution.pdfview.PDFXformCmd
createXFormCmd.findLastCommand
(Class<?> cls) findLastCommand.void
finish()
The entire page is done.Get a list of all annotations of the given type for this PDF pagefloat
get the aspect ratio of the correctly oriented page.getCommand
(int index) get the command at a given indexint
get the current number of commands for this pagegetCommands
(int startIndex) get all the commands in the current page starting at the given indexgetCommands
(int startIndex, int endIndex) Getter for the fieldcommands
.float
get the height of this page, after rotationgetImage
(int width, int height, Rectangle2D clip, ImageObserver observer) Get an image producer which can be used to draw the image represented by this PDFPage.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.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 coordinatesgetUnstretchedSize
(int widthSize, int heightSize, Rectangle2D clip) Get the width and height of this image in the correct aspect ratio.float
getWidth()
get the width of this page, after rotationvoid
stop
(int width, int height, Rectangle2D clip) Stop the rendering of a particular image on this pagevoid
Notify all images we know about that a command has been addedvoid
wait for finish
-
Field Details
-
renderers
a map from image info to weak references to parsers that are active
-
-
Constructor Details
-
PDFPage
create a PDFPage with dimensions in bbox and rotation.- Parameters:
bbox
- aRectangle2D
object.rotation
- aInteger
object.
-
PDFPage
create a PDFPage with dimensions in bbox and rotation.- Parameters:
pageNumber
-Integer
object.bbox
- aRectangle2D
object.rote
-Integer
object.cache
- aCache
object.
-
-
Method Details
-
createImageCmd
createImageCmd.
- Parameters:
image
- aPDFImage
object.- Returns:
- a
PDFImageCmd
object.
-
createPushCmd
public static org.loboevolution.pdfview.PDFPushCmd createPushCmd()createPushCmd.
- Returns:
- a
PDFPushCmd
object.
-
createPopCmd
public static org.loboevolution.pdfview.PDFPopCmd createPopCmd()createPopCmd.
- Returns:
- a
PDFPopCmd
object.
-
createXFormCmd
createXFormCmd.
- Parameters:
at
- aAffineTransform
object.- Returns:
- a
PDFXformCmd
object.
-
getUnstretchedSize
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:
widthSize
- the maximum width of the imageheightSize
- the maximum height of the imageclip
- 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.- Returns:
- a
Dimension
object.
-
getImage
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 producedheight
- the height of the image to be producedclip
- the region in page space of the entire page to displayobserver
- 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 producedheight
- the height of the image to be producedclip
- the region in page space of the entire page to displayobserver
- an image observer who will be notified when the image changes, or nulldrawbg
- 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
-
getAspectRatio
public float getAspectRatio()get the aspect ratio of the correctly oriented page.- Returns:
- the width/height aspect ratio of the page
-
getWidth
public float getWidth()get the width of this page, after rotation- Returns:
- a float.
-
getHeight
public float getHeight()get the height of this page, after rotation- Returns:
- a float.
-
getInitialTransform
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 imageheight
- the height of the imageclip
- the desired clip rectangle (in PDF space) or null to use the page's bounding box- Returns:
- a
AffineTransform
object.
-
getCommandCount
public int getCommandCount()get the current number of commands for this page- Returns:
- a
Integer
object.
-
getCommand
get the command at a given index -
getCommands
get all the commands in the current page starting at the given index -
getCommands
Getter for the field
commands
. -
findLastCommand
findLastCommand.
-
addCommand
Add a single command to the page list.- Parameters:
cmd
- aPDFCmd
object.
-
addCommands
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
- aPDFPage
object.
-
addCommands
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.
-
clearCommands
public void clearCommands()Clear all commands off the current page -
waitForFinish
wait for finish- Throws:
InterruptedException
- if any.
-
stop
Stop the rendering of a particular image on this page- Parameters:
width
- aInteger
object.height
- aInteger
object.clip
- aRectangle2D
object.
-
finish
public void finish()The entire page is done. This must only be invoked once. All observers will be notified. -
addPush
public void addPush()push the graphics state -
addPop
public void addPop()pop the graphics state -
addXform
concatenate a transform to the graphics state- Parameters:
at
- aAffineTransform
object.
-
addStrokeWidth
public org.loboevolution.pdfview.PDFChangeStrokeCmd addStrokeWidth(float w) set the stroke width- Parameters:
w
- the width of the stroke- Returns:
- a
PDFChangeStrokeCmd
object.
-
addEndCap
public void addEndCap(int capstyle) set the end cap style- Parameters:
capstyle
- the cap style: 0 = BUTT, 1 = ROUND, 2 = SQUARE
-
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- Parameters:
limit
- a float.
-
addDash
public void addDash(float[] dashary, float phase) set the dash style- Parameters:
dashary
- the array of on-off lengthsphase
- offset of the array at the start of the line drawing
-
addPath
set the current path- Parameters:
path
- the pathstyle
- the style: PDFShapeCmd.STROKE, PDFShapeCmd.FILL,autoAdjustStroke
- PDFShapeCmd.BOTH, PDFShapeCmd.CLIP, or some combination.
-
addShadeCommand
addShadeCommand.
- Parameters:
p
- aPDFPaint
object.box
- aRectangle2D
object.
-
addFillPaint
set the fill paint- Parameters:
p
- aPDFPaint
object.
-
addStrokePaint
set the stroke paint- Parameters:
p
- aPDFPaint
object.
-
addFillAlpha
public void addFillAlpha(float a) set the fill alpha- Parameters:
a
- a float.
-
addStrokeAlpha
public void addStrokeAlpha(float a) set the stroke alpha- Parameters:
a
- a float.
-
addImage
draw an image- Parameters:
image
- the image to draw
-
updateImages
public void updateImages()Notify all images we know about that a command has been added -
getAnnots
Get a list of all annotations of the given type for this PDF page- Parameters:
type
- aPDFAnnotation.ANNOTATION_TYPE
object.- Returns:
- List of
PDFAnnotation
object.
-
addAnnotations
public void addAnnotations()addAnnotations.
-