Top Description Inners Fields Constructors Methods
org.apache.pdfbox.rendering

public Class PageDrawer

extends PDFGraphicsStreamEngine
Class Inheritance
Imports
java.awt.BasicStroke, .Color, .Graphics, .Graphics2D, .GraphicsConfiguration, .GraphicsDevice, .Image, .Paint, .Point, .Rectangle, .RenderingHints, .Shape, .Stroke, .TexturePaint, .Transparency, java.awt.color.ColorSpace, java.awt.geom.AffineTransform, .Area, .GeneralPath, .Path2D, .PathIterator, .Point2D, .Rectangle2D, java.awt.image.BufferedImage, .ByteLookupTable, .ColorModel, .ComponentColorModel, .DataBuffer, .DataBufferByte, .LookupOp, .LookupTable, .Raster, .WritableRaster, java.io.IOException, java.util.ArrayDeque, .ArrayList, .Deque, .HashMap, .HashSet, .List, .Map, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, org.apache.pdfbox.pdmodel.PDResources, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.common.function.PDFunction, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList, org.apache.pdfbox.pdmodel.font.PDFont, .PDType3Font, .PDVectorFont, org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern, .PDXObject, org.apache.pdfbox.pdmodel.graphics.blend.BlendMode, org.apache.pdfbox.pdmodel.graphics.color.PDColor, .PDColorSpace, .PDDeviceGray, .PDICCBased, .PDPattern, .PDSeparation, org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject, .PDTransparencyGroup, org.apache.pdfbox.pdmodel.graphics.image.PDImage, .PDImageXObject, org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup, .PDOptionalContentGroup.RenderState, .PDOptionalContentMembershipDictionary, org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern, .PDShadingPattern, .PDTilingPattern, org.apache.pdfbox.pdmodel.graphics.shading.PDShading, org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState, .PDGraphicsState, .PDSoftMask, .RenderingMode, org.apache.pdfbox.pdmodel.interactive.annotation.AnnotationFilter, .PDAnnotation, .PDAnnotationUnknown, .PDAppearanceDictionary, org.apache.pdfbox.util.Matrix, .Vector

Paints a page in a PDF document to a Graphics context. May be subclassed to provide custom rendering.

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.

Author
Ben Litchfield

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PageDrawer.TransparencyGroup

Transparency group.

Field Summary

Modifier and TypeField and Description
private AnnotationFilter
annotationFilter

Default annotations filter, returns all annotations

private final Map<COSBase, Boolean>
private int
private final RenderDestination
private boolean
private final Map<PDFont, GlyphCache>
private Graphics2D
private final float
private Shape
private LookupTable
private static final boolean
private static final boolean
private List<Path2D>
private GeneralPath
private static final Log
private int
private static final String
private PDRectangle
private final PDFRenderer
private final RenderingHints
private final boolean
private List<Shape>
private final TilingPaintFactory
private final Deque<PageDrawer.TransparencyGroup>
private AffineTransform
private float
private float

Constructor Summary

AccessConstructor and Description
public
PageDrawer(PageDrawerParameters
Parameters for page drawing.
parameters
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private GeneralPath
adjustClip(GeneralPath linePath)

PDFBOX-5715 / PR#73: This was added to fix a problem with missing fine lines when printing on MacOS.

private BufferedImage
public void
appendRectangle(Point2D
starting coordinate of the rectangle
p0
,
Point2D
second coordinate of the rectangle
p1
,
Point2D
third coordinate of the rectangle
p2
,
Point2D
last coordinate of the rectangle
p3
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.appendRectangle.

Append a rectangle to the current path.

private Paint
applySoftMaskToPaint(Paint parentPaint, PDSoftMask softMask)

private BufferedImage
public void
beginMarkedContentSequence(COSName
indicates the role or significance of the sequence
tag
,
COSDictionary
optional properties
properties
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.beginMarkedContentSequence.

Called when a marked content group begins

public void
beginText()

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.beginText.

Called when the BT operator is encountered.

private void
beginTextClip()

Begin buffering the text clipping path, if any.

private float
clampColor(float color)

public void
clip(int
The winding rule which will be used for clipping.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.clip.

Modify the current clipping path by intersecting it with the current path.

public void
public void
curveTo(float
the X coordinate of the first Bézier control point
x1
,
float
the Y coordinate of the first Bézier control point
y1
,
float
the X coordinate of the second Bézier control point
x2
,
float
the Y coordinate of the second Bézier control point
y2
,
float
the X coordinate of the final end point
x3
,
float
the Y coordinate of the final end point
y3
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.curveTo.

Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.

private void
private void
drawGlyph(GeneralPath
the GeneralPath for the glyph
path
,
PDFont
the font
font
,
int
character code
code
,
Vector
the glyph's displacement (advance)
displacement
,
AffineTransform
the transformation
at
)

Renders a glyph.

public void
drawImage(PDImage
The image to draw.
pdImage
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.drawImage.

Draw the image.

public void
drawPage(Graphics2D
The graphics context to draw onto.
g
,
PDRectangle
The size of the page to draw.
pageSize
)

Draws the page to the requested context.

pack-priv void
drawTilingPattern(Graphics2D
The graphics context to draw onto.
g
,
PDTilingPattern
The tiling pattern to be used.
pattern
,
PDColorSpace
color space for this tiling.
colorSpace
,
PDColor
color for this tiling.
color
,
Matrix
the pattern matrix
patternMatrix
)

Draws the pattern stream to the requested context.

public void
public void
endPath()

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.endPath.

Ends the current path without filling or stroking it.

public void
endText()

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.endText.

Called when the ET operator is encountered.

private void
endTextClip()

End buffering the text clipping path, if any.

public void
fillAndStrokePath(int
The winding rule this path will use.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillAndStrokePath.

Fills and then strokes the path.

public void
fillPath(int
The winding rule this path will use.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

Fill the path.

public AnnotationFilter

Returns:

the AnnotationFilter
getAnnotationFilter
()

Return the AnnotationFilter.

public Point2D
getCurrentPoint()

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.getCurrentPoint.

Returns the current point of the current path.

private float[]
protected final Graphics2D

Returns:

the underlying Graphics2D
getGraphics
()

Returns the underlying Graphics2D.

private LookupTable
protected final GeneralPath

Returns:

the current line path
getLinePath
()

Returns the current line path.

protected final Paint

Returns:

The non-stroking AWT Paint.
getNonStrokingPaint
()

Returns the non-stroking AWT Paint.

protected Paint

Returns:

an AWT paint for the given PDColor
getPaint
(PDColor
The color to get a paint for. This can be an actual color or a pattern.
color
)

Returns an AWT paint for the given PDColor.

public final PDFRenderer

Returns:

the parent renderer
getRenderer
()

Returns the parent renderer.

private Stroke
private Paint
protected int

Returns:

The rounded-down ratio of image pixels to drawn pixels. Returned value will always be >=1.
getSubsampling
(PDImage
PDImage to be drawn
pdImage
,
AffineTransform
Transform that will be applied to the image when drawing
at
)

Calculates the subsampling frequency for a given PDImage based on the current transformation and its calculated transform.

private boolean
private void
private boolean
isAllZeroDash(float[] dashArray)

private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
isRectangular(GeneralPath path)

Returns true if the given path is rectangular.

public void
lineTo(float
the X-coordinate of the ending-point of the line to be drawn
x
,
float
the Y-coordinate of the ending-point of the line to be drawn
y
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.lineTo.

Draws a line from the current point to (x,y).

public void
moveTo(float
the x-coordinate to move to
x
,
float
the y-coordinate to move to
y
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.moveTo.

Starts a new path at (x,y).

public void
setAnnotationFilter(AnnotationFilter
the AnnotationFilter
annotationFilter
)

Set the AnnotationFilter.

protected final void
setClip()

Sets the clipping path using caching for performance.

private void
setRenderingHints()

Sets high-quality rendering hints on the current Graphics2D.

public void
shadingFill(COSName
The name of the Shading Dictionary to use for this fill instruction.
shadingName
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.shadingFill.

Fill with Shading.

public void
showAnnotation(PDAnnotation
An annotation on the current page.
annotation
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showAnnotation.

Shows the given annotation.

protected void
showFontGlyph(Matrix
the current text rendering matrix, Trm
textRenderingMatrix
,
PDFont
the current font
font
,
int
internal PDF character code for the glyph
code
,
Vector
the displacement (i.e. advance) of the glyph in text space
displacement
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showFontGlyph.

Called when a glyph is to be processed.

public void
showForm(PDFormXObject
form XObject
form
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showForm.

Shows a form from the content stream.

public void
showTransparencyGroup(PDTransparencyGroup
transparency group (form) XObject
form
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showTransparencyGroup.

Shows a transparency group from the content stream.

protected void
showTransparencyGroupOnGraphics(PDTransparencyGroup
the transparency group to be extracted
form
,
Graphics2D
the target graphics device
graphics
)

For advanced users, to extract the transparency group into a separate graphics device.

protected void
showType3Glyph(Matrix
the current text rendering matrix, Trm
textRenderingMatrix
,
PDType3Font
the current font
font
,
int
internal PDF character code for the glyph
code
,
Vector
the displacement (i.e. advance) of the glyph in text space
displacement
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showType3Glyph.

Called when a glyph is to be processed.

public void
protected void
transferClip(Graphics2D
graphics device
graphics
)

Transfer clip to the destination device.

Inherited from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine:
getPage