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 override
PDFRenderer.createPageDrawer(PageDrawerParameters)
. See the OpaquePDFRenderer.java
example in the source code download on how to do this.
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(Graphics2D 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.
|
protected int |
getSubsampling(PDImage pdImage,
AffineTransform at)
Calculates the subsampling frequency for a given PDImage based on the current transformation
and its calculated transform.
|
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, isShouldProcessColorOperators, markedContentPoint, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showGlyph, showText, showTextString, showTextStrings, 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(Graphics2D 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
- if the AWT paint could not be createdprotected 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
- starting coordinate of the rectanglep1
- second coordinate of the rectanglep2
- third coordinate of the rectanglep3
- last coordinate of the rectangleprotected final Paint getNonStrokingPaint() throws IOException
showGlyph()
. See
PDFBOX-5093 for more.IOException
- if the non-stroking AWT Paint could not be createdpublic 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 the path could not be filledpublic 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
- the x-coordinate to move toy
- the y-coordinate to move topublic void lineTo(float x, float y)
PDFGraphicsStreamEngine
lineTo
in class PDFGraphicsStreamEngine
x
- the X-coordinate of the ending-point of the line to be drawny
- the Y-coordinate of the ending-point of the line to be drawnpublic void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
PDFGraphicsStreamEngine
curveTo
in class PDFGraphicsStreamEngine
x1
- the X coordinate of the first Bézier control pointy1
- the Y coordinate of the first Bézier control pointx2
- the X coordinate of the second Bézier control pointy2
- the Y coordinate of the second Bézier control pointx3
- the X coordinate of the final end pointy3
- the Y coordinate of the final end pointpublic 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 the image could not be drawnprotected int getSubsampling(PDImage pdImage, AffineTransform at)
pdImage
- PDImage to be drawnat
- Transform that will be applied to the image when drawingpublic 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 the path could not be filled using the given shadingpublic 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
- the transparency group to be extractedgraphics
- the target graphics deviceIOException
- if the transparency group could not be extractedpublic 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–2025 The Apache Software Foundation. All rights reserved.