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

public Class CustomPageDrawer

extends Object
Class Inheritance
Imports
java.awt.BasicStroke, .Color, .Graphics2D, .Paint, .Shape, .Stroke, java.awt.geom.AffineTransform, .Rectangle2D, java.awt.image.BufferedImage, java.io.File, .IOException, javax.imageio.ImageIO, org.apache.pdfbox.Loader, org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.font.PDFont, org.apache.pdfbox.pdmodel.graphics.color.PDColor, .PDPattern, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation, org.apache.pdfbox.rendering.PDFRenderer, .PageDrawer, .PageDrawerParameters, org.apache.pdfbox.util.Matrix, .Vector

Example showing custom rendering by subclassing PageDrawer.

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.

Author
John Hewson

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CustomPageDrawer.MyPageDrawer

Example PageDrawer subclass with custom rendering.

private static class
CustomPageDrawer.MyPDFRenderer

Example PDFRenderer subclass, uses MyPageDrawer for custom rendering.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
main(String[] args)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CustomPageDrawerback to summary
public CustomPageDrawer()

Method Detail

mainback to summary
public static void main(String[] args) throws IOException
org.apache.pdfbox.examples.rendering back to summary

private Class CustomPageDrawer.MyPageDrawer

extends PageDrawer
Class Inheritance

Example PageDrawer subclass with custom rendering.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
fillPath(int
The winding rule this path will use.
windingRule
)

Overrides org.apache.pdfbox.rendering.PageDrawer.fillPath.

Filled path bounding boxes.

protected Paint
getPaint(PDColor
The color to get a paint for. This can be an actual color or a pattern.
color
)

Overrides org.apache.pdfbox.rendering.PageDrawer.getPaint.

Color replacement.

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

Overrides org.apache.pdfbox.rendering.PageDrawer.showAnnotation.

Custom annotation rendering.

protected void
showGlyph(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.showGlyph.

Glyph bounding boxes.

Inherited from org.apache.pdfbox.rendering.PageDrawer:
appendRectanglebeginMarkedContentSequencebeginTextclipclosePathcurveTodrawImagedrawPageendMarkedContentSequenceendPathendTextfillAndStrokePathgetAnnotationFiltergetCurrentPointgetGraphicsgetLinePathgetNonStrokingPaintgetRenderergetSubsamplinglineTomoveTosetAnnotationFiltersetClipshadingFillshowFontGlyphshowFormshowTransparencyGroupshowTransparencyGroupOnGraphicsshowType3GlyphstrokePathtransferClip

Constructor Detail

MyPageDrawerback to summary
pack-priv MyPageDrawer(PageDrawerParameters parameters) throws IOException

Method Detail

fillPathback to summary
public void fillPath(int windingRule) throws IOException

Overrides org.apache.pdfbox.rendering.PageDrawer.fillPath.

Filled path bounding boxes.

Parameters
windingRule:int

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

The winding rule this path will use.

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

if the path could not be filled

getPaintback to summary
protected Paint getPaint(PDColor color) throws IOException

Overrides org.apache.pdfbox.rendering.PageDrawer.getPaint.

Color replacement.

Parameters
color:PDColor

Doc from org.apache.pdfbox.rendering.PageDrawer.getPaint.

The color to get a paint for. This can be an actual color or a pattern.

Returns:Paint

Doc from org.apache.pdfbox.rendering.PageDrawer.getPaint.

an AWT paint for the given PDColor

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.pdfbox.rendering.PageDrawer.getPaint.

if the AWT paint could not be created

showAnnotationback to summary
public void showAnnotation(PDAnnotation annotation) throws IOException

Overrides org.apache.pdfbox.rendering.PageDrawer.showAnnotation.

Custom annotation rendering.

Parameters
annotation:PDAnnotation

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showAnnotation.

An annotation on the current page.

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showAnnotation.

If an error occurred reading the annotation

showGlyphback to summary
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

Glyph bounding boxes.

Parameters
textRenderingMatrix:Matrix

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

the current text rendering matrix, Trm

font:PDFont

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

the current font

code:int

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

internal PDF character code for the glyph

displacement:Vector

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

the displacement (i.e. advance) of the glyph in text space

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

if the glyph cannot be processed

org.apache.pdfbox.examples.rendering back to summary

private Class CustomPageDrawer.MyPDFRenderer

extends PDFRenderer
Class Inheritance

Example PDFRenderer subclass, uses MyPageDrawer for custom rendering.

Field Summary

Inherited from org.apache.pdfbox.rendering.PDFRenderer:
document

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected PageDrawer
createPageDrawer(PageDrawerParameters
parameters to be used when creating the PageDrawer instance
parameters
)

Overrides org.apache.pdfbox.rendering.PDFRenderer.createPageDrawer.

Returns a new PageDrawer instance, using the given parameters.

Inherited from org.apache.pdfbox.rendering.PDFRenderer:
getAnnotationsFiltergetDefaultDestinationgetImageDownscalingOptimizationThresholdgetRenderingHintsisGroupEnabledisSubsamplingAllowedrenderImagerenderImagerenderImagerenderImagerenderImageWithDPIrenderImageWithDPIrenderPageToGraphicsrenderPageToGraphicsrenderPageToGraphicsrenderPageToGraphicssetAnnotationsFiltersetDefaultDestinationsetImageDownscalingOptimizationThresholdsetRenderingHintssetSubsamplingAllowed

Constructor Detail

MyPDFRendererback to summary
pack-priv MyPDFRenderer(PDDocument document)

Method Detail

createPageDrawerback to summary
protected PageDrawer createPageDrawer(PageDrawerParameters parameters) throws IOException

Overrides org.apache.pdfbox.rendering.PDFRenderer.createPageDrawer.

Doc from org.apache.pdfbox.rendering.PDFRenderer.createPageDrawer.

Returns a new PageDrawer instance, using the given parameters. May be overridden.

Parameters
parameters:PageDrawerParameters

parameters to be used when creating the PageDrawer instance

Returns:PageDrawer

a new PageDrawer instance

Annotations
@Override
Exceptions
IOException:
id the PageDrawer instance could not be created