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 PDFGraphicsStreamEngine instead. Subclassing PageDrawer is only suitable for cases where the goal is to render onto a Canvas surface.
-
-
Constructor Summary
Constructors Constructor Description PageDrawer(PageDrawerParameters parameters)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendRectangle(android.graphics.PointF p0, android.graphics.PointF p1, android.graphics.PointF p2, android.graphics.PointF p3)Append a rectangle to the current path.voidbeginText()Called when the BT operator is encountered.voidclip(android.graphics.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(android.graphics.Paint p, android.graphics.Canvas c, PDRectangle pageSize)Draws the page to the requested canvas.voidendPath()Ends the current path without filling or stroking it.voidendText()Called when the ET operator is encountered.voidfillAndStrokePath(android.graphics.Path.FillType windingRule)Fills and then strokes the path.voidfillPath(android.graphics.Path.FillType windingRule)Fill the path.protected android.graphics.CanvasgetCanvas()Returns the underlying Canvas.android.graphics.PointFgetCurrentPoint()Returns the current point of the current path.protected android.graphics.PathgetLinePath()Returns the current line path.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).voidshadingFill(COSName shadingName)Fill with Shading.voidshowAnnotation(PDAnnotation annotation)Shows the given annotation.protected voidshowFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement)Called when a glyph is to be processed.This method is intended for overriding in subclasses, the default implementation does nothing.voidshowTransparencyGroup(PDFormXObject form)Shows a transparency group from the content stream.voidstrokePath()Stroke the path.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from class com.tom_roush.pdfbox.contentstream.PDFGraphicsStreamEngine
getPage
-
Methods inherited from class com.tom_roush.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getResources, getTextLineMatrix, getTextMatrix, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, registerOperatorProcessor, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showForm, 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
-
getRenderer
public final PDFRenderer getRenderer()
Returns the parent renderer.
-
getCanvas
protected final android.graphics.Canvas getCanvas()
Returns the underlying Canvas. May be null if drawPage has not yet been called.
-
getLinePath
protected final android.graphics.Path getLinePath()
Returns the current line path. This is reset to empty after each fill/stroke.
-
drawPage
public void drawPage(android.graphics.Paint p, android.graphics.Canvas c, PDRectangle pageSize) throws IOExceptionDraws 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.
-
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, String unicode, 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 glyphunicode- the Unicode text for this glyph, or null if the PDF does provide itdisplacement- the displacement (i.e. advance) of the glyph in text space- Throws:
IOException- if the glyph cannot be processed
-
appendRectangle
public void appendRectangle(android.graphics.PointF p0, android.graphics.PointF p1, android.graphics.PointF p2, android.graphics.PointF p3)Description copied from class:PDFGraphicsStreamEngineAppend a rectangle to the current path.- Specified by:
appendRectanglein classPDFGraphicsStreamEngine
-
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(android.graphics.Path.FillType windingRule) throws IOExceptionDescription copied from class:PDFGraphicsStreamEngineFill the path.- Specified by:
fillPathin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule this path will use.- Throws:
IOException
-
fillAndStrokePath
public void fillAndStrokePath(android.graphics.Path.FillType windingRule) throws IOExceptionFills 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(android.graphics.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
-
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
-
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
-
getCurrentPoint
public android.graphics.PointF getCurrentPoint()
Description copied from class:PDFGraphicsStreamEngineReturns the current point of the current path.- Specified by:
getCurrentPointin classPDFGraphicsStreamEngine
-
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
-
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
-
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
-
showTransparencyGroup
public void showTransparencyGroup(PDFormXObject 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
-
-