Package com.tom_roush.pdfbox.rendering
Class PageDrawer
- java.lang.Object
-
- com.tom_roush.pdfbox.contentstream.PDFStreamEngine
-
- com.tom_roush.pdfbox.contentstream.PDFGraphicsStreamEngine
-
- com.tom_roush.pdfbox.rendering.PageDrawer
-
public class PageDrawer extends PDFGraphicsStreamEngine
Paints a page in a PDF document to a Canvas context. May be subclassed to provide custom rendering.If you want to do custom graphics processing rather than Canvas rendering, then you should subclass
PDFGraphicsStreamEngineinstead. Subclassing PageDrawer is only suitable for cases where the goal is to render onto aCanvassurface. In that case you'll also have to subclassPDFRendererand overridePDFRenderer.createPageDrawer(PageDrawerParameters). See the OpaquePDFRenderer.java example in the source code download on how to do this.
-
-
Constructor Summary
Constructors Constructor Description PageDrawer(PageDrawerParameters parameters)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendRectangle(PointF p0, PointF p1, PointF p2, PointF p3)Append a rectangle to the current path.voidbeginMarkedContentSequence(COSName tag, COSDictionary properties)Called when a marked content group beginsvoidbeginText()Called when the BT operator is encountered.voidclip(Path.FillType windingRule)Modify the current clipping path by intersecting it with the current path.voidclosePath()Closes the current path.voidcurveTo(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.voiddrawImage(PDImage pdImage)Draw the image.voiddrawPage(Paint p, Canvas c, PDRectangle pageSize)Draws the page to the requested Canvas.voidendMarkedContentSequence()Called when a marked content group endsvoidendPath()Ends the current path without filling or stroking it.voidendText()Called when the ET operator is encountered.voidfillAndStrokePath(Path.FillType windingRule)Fills and then strokes the path.voidfillPath(Path.FillType windingRule)Fill the path.AnnotationFiltergetAnnotationFilter()Return the AnnotationFilter.protected CanvasgetCanvas()Returns the underlying Canvas.PointFgetCurrentPoint()Returns the current point of the current path.protected PathgetLinePath()Returns the current line path.protected intgetNonStrokingColor()PDFRenderergetRenderer()Returns the parent renderer.voidlineTo(float x, float y)Draws a line from the current point to (x,y).voidmoveTo(float x, float y)Starts a new path at (x,y).voidsetAnnotationFilter(AnnotationFilter annotationFilter)Set the AnnotationFilter.protected voidsetClip()Sets the clipping path using caching for performance.voidsetStroke(Paint p, float width, Paint.Cap cap, Paint.Join join, float miterLimit, float[] dash, float dash_phase)voidshadingFill(COSName shadingName)Fill with Shading.voidshowAnnotation(PDAnnotation annotation)Shows the given annotation.protected voidshowFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement)Called when a glyph is to be processed.voidshowForm(PDFormXObject form)Shows a form from the content stream.voidshowTransparencyGroup(PDTransparencyGroup form)Shows a transparency group from the content stream.protected voidshowTransparencyGroupOnCanvas(PDTransparencyGroup form, Canvas canvas)For advanced users, to extract the transparency group into a separate graphics device.protected voidshowType3Glyph(Matrix textRenderingMatrix, PDType3Font font, int code, Vector displacement)Called when a glyph is to be processed.voidstrokePath()Stroke the path.-
Methods inherited from class com.tom_roush.pdfbox.contentstream.PDFGraphicsStreamEngine
getPage
-
Methods inherited from class com.tom_roush.pdfbox.contentstream.PDFStreamEngine
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
-
-
-
-
Constructor Detail
-
PageDrawer
public PageDrawer(PageDrawerParameters parameters) throws IOException
Constructor.- Parameters:
parameters- Parameters for page drawing.- Throws:
IOException- If there is an error loading properties from the file.
-
-
Method Detail
-
getAnnotationFilter
public AnnotationFilter getAnnotationFilter()
Return the AnnotationFilter.- Returns:
- the AnnotationFilter
-
setAnnotationFilter
public void setAnnotationFilter(AnnotationFilter annotationFilter)
Set the AnnotationFilter.Allows to only render annotation accepted by the filter.
- Parameters:
annotationFilter- the AnnotationFilter
-
getRenderer
public final PDFRenderer getRenderer()
Returns the parent renderer.
-
getCanvas
protected final Canvas getCanvas()
Returns the underlying Canvas. May be null if drawPage has not yet been called.
-
getLinePath
protected final Path getLinePath()
Returns the current line path. This is reset to empty after each fill/stroke.
-
drawPage
public void drawPage(Paint p, Canvas c, PDRectangle pageSize) throws IOException
Draws the page to the requested Canvas.- Parameters:
p- The paint.c- The canvas to draw onto.pageSize- The size of the page to draw.- Throws:
IOException- If there is an IO error while drawing the page.
-
setClip
protected final void setClip()
Sets the clipping path using caching for performance. We track lastClip manually becauseGraphics2D#getClip()returns a new object instead of the same one passed tosetClip(). You may need to call this if you overrideshowGlyph(). See PDFBOX-5093 for more.
-
beginText
public void beginText() throws IOExceptionDescription copied from class:PDFStreamEngineCalled when the BT operator is encountered. This method is for overriding in subclasses, the default implementation does nothing.- Overrides:
beginTextin classPDFStreamEngine- Throws:
IOException- if there was an error processing the text
-
endText
public void endText() throws IOExceptionDescription copied from class:PDFStreamEngineCalled when the ET operator is encountered. This method is for overriding in subclasses, the default implementation does nothing.- Overrides:
endTextin classPDFStreamEngine- Throws:
IOException- if there was an error processing the text
-
showFontGlyph
protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException
Description copied from class:PDFStreamEngineCalled when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.- Overrides:
showFontGlyphin classPDFStreamEngine- Parameters:
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 space- Throws:
IOException- if the glyph cannot be processed
-
showType3Glyph
protected void showType3Glyph(Matrix textRenderingMatrix, PDType3Font font, int code, Vector displacement) throws IOException
Description copied from class:PDFStreamEngineCalled when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.- Overrides:
showType3Glyphin classPDFStreamEngine- Parameters:
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 space- Throws:
IOException- if the glyph cannot be processed
-
appendRectangle
public void appendRectangle(PointF p0, PointF p1, PointF p2, PointF p3)
Description copied from class:PDFGraphicsStreamEngineAppend a rectangle to the current path.- Specified by:
appendRectanglein classPDFGraphicsStreamEngine- Parameters:
p0- point P0 of the rectangle.p1- point P1 of the rectangle.p2- point P2 of the rectangle.p3- point P3 of the rectangle.
-
getNonStrokingColor
protected final int getNonStrokingColor() throws IOException- Throws:
IOException
-
strokePath
public void strokePath() throws IOExceptionDescription copied from class:PDFGraphicsStreamEngineStroke the path.- Specified by:
strokePathin classPDFGraphicsStreamEngine- Throws:
IOException- If there is an IO error while stroking the path.
-
fillPath
public void fillPath(Path.FillType windingRule) throws IOException
Description copied from class:PDFGraphicsStreamEngineFill the path.- Specified by:
fillPathin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule this path will use.- Throws:
IOException- if something went wrong.
-
fillAndStrokePath
public void fillAndStrokePath(Path.FillType windingRule) throws IOException
Fills and then strokes the path.- Specified by:
fillAndStrokePathin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule this path will use.- Throws:
IOException- If there is an IO error while filling the path.
-
clip
public void clip(Path.FillType windingRule)
Description copied from class:PDFGraphicsStreamEngineModify the current clipping path by intersecting it with the current path. The clipping path will not be updated until the succeeding painting operator is called.- Specified by:
clipin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule which will be used for clipping.
-
moveTo
public void moveTo(float x, float y)Description copied from class:PDFGraphicsStreamEngineStarts a new path at (x,y).- Specified by:
moveToin classPDFGraphicsStreamEngine- Parameters:
x- x-coordinate of the target point.y- y-coordinate of the target point.
-
lineTo
public void lineTo(float x, float y)Description copied from class:PDFGraphicsStreamEngineDraws a line from the current point to (x,y).- Specified by:
lineToin classPDFGraphicsStreamEngine- Parameters:
x- x-coordinate of the end point of the line.y- y-coordinate of the end point of the line.
-
curveTo
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)Description copied from class:PDFGraphicsStreamEngineDraws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.- Specified by:
curveToin classPDFGraphicsStreamEngine- Parameters:
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.
-
getCurrentPoint
public PointF getCurrentPoint()
Description copied from class:PDFGraphicsStreamEngineReturns the current point of the current path.- Specified by:
getCurrentPointin classPDFGraphicsStreamEngine- Returns:
- the current point.
-
closePath
public void closePath()
Description copied from class:PDFGraphicsStreamEngineCloses the current path.- Specified by:
closePathin classPDFGraphicsStreamEngine
-
endPath
public void endPath()
Description copied from class:PDFGraphicsStreamEngineEnds the current path without filling or stroking it. The clipping path is updated here.- Specified by:
endPathin classPDFGraphicsStreamEngine
-
drawImage
public void drawImage(PDImage pdImage) throws IOException
Description copied from class:PDFGraphicsStreamEngineDraw the image.- Specified by:
drawImagein classPDFGraphicsStreamEngine- Parameters:
pdImage- The image to draw.- Throws:
IOException- if something went wrong.
-
shadingFill
public void shadingFill(COSName shadingName) throws IOException
Description copied from class:PDFGraphicsStreamEngineFill with Shading.- Specified by:
shadingFillin classPDFGraphicsStreamEngine- Parameters:
shadingName- The name of the Shading Dictionary to use for this fill instruction.- Throws:
IOException- if something went wrong.
-
showAnnotation
public void showAnnotation(PDAnnotation annotation) throws IOException
Description copied from class:PDFStreamEngineShows the given annotation.- Overrides:
showAnnotationin classPDFStreamEngine- Parameters:
annotation- An annotation on the current page.- Throws:
IOException- If an error occurred reading the annotation
-
showForm
public void showForm(PDFormXObject form) throws IOException
Shows a form from the content stream.- Overrides:
showFormin classPDFStreamEngine- Parameters:
form- form XObject- Throws:
IOException- if the form cannot be processed
-
setStroke
public void setStroke(Paint p, float width, Paint.Cap cap, Paint.Join join, float miterLimit, float[] dash, float dash_phase)
-
showTransparencyGroup
public void showTransparencyGroup(PDTransparencyGroup form) throws IOException
Description copied from class:PDFStreamEngineShows a transparency group from the content stream.- Overrides:
showTransparencyGroupin classPDFStreamEngine- Parameters:
form- transparency group (form) XObject- Throws:
IOException- if the transparency group cannot be processed
-
showTransparencyGroupOnCanvas
protected void showTransparencyGroupOnCanvas(PDTransparencyGroup form, Canvas canvas) throws IOException
For advanced users, to extract the transparency group into a separate graphics device.- Parameters:
form-canvas-- Throws:
IOException
-
beginMarkedContentSequence
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
Called when a marked content group begins- Overrides:
beginMarkedContentSequencein classPDFStreamEngine- Parameters:
tag- indicates the role or significance of the sequenceproperties- optional properties
-
endMarkedContentSequence
public void endMarkedContentSequence()
Called when a marked content group ends- Overrides:
endMarkedContentSequencein classPDFStreamEngine
-
-