public class PageDrawer extends PDFGraphicsStreamEngine
If you want to do custom graphics processing rather than Graphics2D rendering, then you should
subclass PDFGraphicsStreamEngine
instead. Subclassing PageDrawer is only suitable for
cases where the goal is to render onto a Graphics2D
surface. In that case you'll also
have to subclass PDFRenderer
and modify
PDFRenderer.createPageDrawer(PageDrawerParameters)
.
Constructor and Description |
---|
PageDrawer(PageDrawerParameters parameters)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
appendRectangle(Point2D p0,
Point2D p1,
Point2D p2,
Point2D p3)
Append a rectangle to the current path.
|
void |
beginMarkedContentSequence(COSName tag,
COSDictionary properties)
Called when a marked content group begins
|
void |
beginText()
Called when the BT operator is encountered.
|
void |
clip(int windingRule)
Modify the current clipping path by intersecting it with the current path.
|
void |
closePath()
Closes the current path.
|
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.
|
void |
drawImage(PDImage pdImage)
Draw the image.
|
void |
drawPage(Graphics g,
PDRectangle pageSize)
Draws the page to the requested context.
|
void |
endMarkedContentSequence()
Called when a marked content group ends
|
void |
endPath()
Ends the current path without filling or stroking it.
|
void |
endText()
Called when the ET operator is encountered.
|
void |
fillAndStrokePath(int windingRule)
Fills and then strokes the path.
|
void |
fillPath(int windingRule)
Fill the path.
|
AnnotationFilter |
getAnnotationFilter()
Return the AnnotationFilter.
|
Point2D |
getCurrentPoint()
Returns the current point of the current path.
|
protected Graphics2D |
getGraphics()
Returns the underlying Graphics2D.
|
protected GeneralPath |
getLinePath()
Returns the current line path.
|
protected Paint |
getNonStrokingPaint()
Returns the non-stroking AWT Paint.
|
protected Paint |
getPaint(PDColor color)
Returns an AWT paint for the given PDColor.
|
PDFRenderer |
getRenderer()
Returns the parent renderer.
|
void |
lineTo(float x,
float y)
Draws a line from the current point to (x,y).
|
void |
moveTo(float x,
float y)
Starts a new path at (x,y).
|
void |
setAnnotationFilter(AnnotationFilter annotationFilter)
Set the AnnotationFilter.
|
protected void |
setClip()
Sets the clipping path using caching for performance.
|
void |
shadingFill(COSName shadingName)
Fill with Shading.
|
void |
showAnnotation(PDAnnotation annotation)
Shows the given annotation.
|
protected void |
showFontGlyph(Matrix textRenderingMatrix,
PDFont font,
int code,
Vector displacement)
Called when a glyph is to be processed.
|
void |
showForm(PDFormXObject form)
Shows a form from the content stream.
|
void |
showTransparencyGroup(PDTransparencyGroup form)
Shows a transparency group from the content stream.
|
protected void |
showTransparencyGroupOnGraphics(PDTransparencyGroup form,
Graphics2D graphics)
For advanced users, to extract the transparency group into a separate graphics device.
|
protected void |
showType3Glyph(Matrix textRenderingMatrix,
PDType3Font font,
int code,
Vector displacement)
Called when a glyph is to be processed.
|
void |
strokePath()
Stroke the path.
|
protected void |
transferClip(Graphics2D graphics)
Transfer clip to the destination device.
|
getPage
addOperator, applyTextAdjustment, decreaseLevel, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, registerOperatorProcessor, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showFontGlyph, showGlyph, showGlyph, showText, showTextString, showTextStrings, showType3Glyph, transformedPoint, transformWidth, unsupportedOperator
public PageDrawer(PageDrawerParameters parameters) throws IOException
parameters
- Parameters for page drawing.IOException
- If there is an error loading properties from the file.public AnnotationFilter getAnnotationFilter()
public void setAnnotationFilter(AnnotationFilter annotationFilter)
Allows to only render annotation accepted by the filter.
annotationFilter
- the AnnotationFilterpublic final PDFRenderer getRenderer()
protected final Graphics2D getGraphics()
protected final GeneralPath getLinePath()
public void drawPage(Graphics g, PDRectangle pageSize) throws IOException
g
- The graphics context to draw onto.pageSize
- The size of the page to draw.IOException
- If there is an IO error while drawing the page.protected Paint getPaint(PDColor color) throws IOException
color
- The color to get a paint for. This can be an actual color or a pattern.IOException
protected final void setClip()
Graphics.getClip()
returns a new object instead of the same one passed to
setClip()
. You may need to call this if you
override showGlyph()
. See
PDFBOX-5093 for more.protected void transferClip(Graphics2D graphics)
PDGraphicsState.getCurrentClippingPaths()
. See
PDFBOX-5258 for sample code.graphics
- graphics devicepublic void beginText() throws IOException
PDFStreamEngine
beginText
in class PDFStreamEngine
IOException
- if there was an error processing the textpublic void endText() throws IOException
PDFStreamEngine
endText
in class PDFStreamEngine
IOException
- if there was an error processing the textprotected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException
PDFStreamEngine
showFontGlyph
in class PDFStreamEngine
textRenderingMatrix
- the current text rendering matrix, Trmfont
- the current fontcode
- internal PDF character code for the glyphdisplacement
- the displacement (i.e. advance) of the glyph in text spaceIOException
- if the glyph cannot be processedprotected void showType3Glyph(Matrix textRenderingMatrix, PDType3Font font, int code, Vector displacement) throws IOException
PDFStreamEngine
showType3Glyph
in class PDFStreamEngine
textRenderingMatrix
- the current text rendering matrix, Trmfont
- the current fontcode
- internal PDF character code for the glyphdisplacement
- the displacement (i.e. advance) of the glyph in text spaceIOException
- if the glyph cannot be processedpublic void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3)
PDFGraphicsStreamEngine
appendRectangle
in class PDFGraphicsStreamEngine
p0
- point P0 of the rectangle.p1
- point P1 of the rectangle.p2
- point P2 of the rectangle.p3
- point P3 of the rectangle.protected final Paint getNonStrokingPaint() throws IOException
showGlyph()
. See
PDFBOX-5093 for more.IOException
public void strokePath() throws IOException
PDFGraphicsStreamEngine
strokePath
in class PDFGraphicsStreamEngine
IOException
- If there is an IO error while stroking the path.public void fillPath(int windingRule) throws IOException
PDFGraphicsStreamEngine
fillPath
in class PDFGraphicsStreamEngine
windingRule
- The winding rule this path will use.IOException
- if something went wrong.public void fillAndStrokePath(int windingRule) throws IOException
fillAndStrokePath
in class PDFGraphicsStreamEngine
windingRule
- The winding rule this path will use.IOException
- If there is an IO error while filling the path.public void clip(int windingRule)
PDFGraphicsStreamEngine
clip
in class PDFGraphicsStreamEngine
windingRule
- The winding rule which will be used for clipping.public void moveTo(float x, float y)
PDFGraphicsStreamEngine
moveTo
in class PDFGraphicsStreamEngine
x
- x-coordinate of the target point.y
- y-coordinate of the target point.public void lineTo(float x, float y)
PDFGraphicsStreamEngine
lineTo
in class PDFGraphicsStreamEngine
x
- x-coordinate of the end point of the line.y
- y-coordinate of the end point of the line.public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
PDFGraphicsStreamEngine
curveTo
in class PDFGraphicsStreamEngine
x1
- x-coordinate of the first control point.y1
- y-coordinate of the first control point.x2
- x-coordinate of the second control point.y2
- y-coordinate of the second control point.x3
- x-coordinate of the end point of the curve.y3
- y-coordinate of the end point of the curve.public Point2D getCurrentPoint()
PDFGraphicsStreamEngine
getCurrentPoint
in class PDFGraphicsStreamEngine
public void closePath()
PDFGraphicsStreamEngine
closePath
in class PDFGraphicsStreamEngine
public void endPath()
PDFGraphicsStreamEngine
endPath
in class PDFGraphicsStreamEngine
public void drawImage(PDImage pdImage) throws IOException
PDFGraphicsStreamEngine
drawImage
in class PDFGraphicsStreamEngine
pdImage
- The image to draw.IOException
- if something went wrong.public void shadingFill(COSName shadingName) throws IOException
PDFGraphicsStreamEngine
shadingFill
in class PDFGraphicsStreamEngine
shadingName
- The name of the Shading Dictionary to use for this fill instruction.IOException
- if something went wrong.public void showAnnotation(PDAnnotation annotation) throws IOException
PDFStreamEngine
showAnnotation
in class PDFStreamEngine
annotation
- An annotation on the current page.IOException
- If an error occurred reading the annotationpublic void showForm(PDFormXObject form) throws IOException
showForm
in class PDFStreamEngine
form
- form XObjectIOException
- if the form cannot be processedpublic void showTransparencyGroup(PDTransparencyGroup form) throws IOException
PDFStreamEngine
showTransparencyGroup
in class PDFStreamEngine
form
- transparency group (form) XObjectIOException
- if the transparency group cannot be processedprotected void showTransparencyGroupOnGraphics(PDTransparencyGroup form, Graphics2D graphics) throws IOException
form
- graphics
- IOException
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
beginMarkedContentSequence
in class PDFStreamEngine
tag
- indicates the role or significance of the sequenceproperties
- optional propertiespublic void endMarkedContentSequence()
endMarkedContentSequence
in class PDFStreamEngine
Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.