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

public Class CustomGraphicsStreamEngine

extends PDFGraphicsStreamEngine
Class Inheritance
Imports
java.awt.geom.Point2D, java.io.File, .IOException, org.apache.pdfbox.Loader, org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine, .PDFStreamEngine, org.apache.pdfbox.cos.COSArray, .COSName, org.apache.pdfbox.pdmodel.PDDocument, .PDPage, org.apache.pdfbox.pdmodel.font.PDFont, org.apache.pdfbox.pdmodel.graphics.image.PDImage, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation, org.apache.pdfbox.util.Matrix, .Vector

Example of a custom PDFGraphicsStreamEngine subclass. Allows text and graphics to be processed in a custom manner. This example simply prints the operations to stdout.

See PDFStreamEngine for further methods which may be overridden.

Author
John Hewson

Constructor Summary

AccessConstructor and Description
protected
CustomGraphicsStreamEngine(PDPage
PDF Page
page
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
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.

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.

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

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

Draw the image.

public void
endPath()

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

Ends the current path without filling or stroking it.

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 Point2D
getCurrentPoint()

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

Returns the current point of the current path.

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 static void
main(String[] args)

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
run()

Runs the engine on the current page.

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.

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.

Overridden from PDFStreamEngine.

public void
showTextString(byte[]
the encoded text
string
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showTextString.

Overridden from PDFStreamEngine.

public void
showTextStrings(COSArray
array of encoded text strings and adjustments
array
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showTextStrings.

Overridden from PDFStreamEngine.

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

Constructor Detail

CustomGraphicsStreamEngineback to summary
protected CustomGraphicsStreamEngine(PDPage page)

Constructor.

Parameters
page:PDPage

PDF Page

Method Detail

appendRectangleback to summary
public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) throws IOException

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

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

Append a rectangle to the current path.

Parameters
p0:Point2D

starting coordinate of the rectangle

p1:Point2D

second coordinate of the rectangle

p2:Point2D

third coordinate of the rectangle

p3:Point2D

last coordinate of the rectangle

Annotations
@Override
Exceptions
IOException:
if the rectangle could not be appended
clipback to summary
public void clip(int windingRule) throws IOException

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

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

Modify 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.

Parameters
windingRule:int

The winding rule which will be used for clipping.

Annotations
@Override
Exceptions
IOException:
if the clipping path could not be modified
closePathback to summary
public void closePath() throws IOException

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

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

Closes the current path.

Annotations
@Override
Exceptions
IOException:
if the current path could not be closed
curveToback to summary
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws IOException

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

Doc from 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.

Parameters
x1:float

the X coordinate of the first Bézier control point

y1:float

the Y coordinate of the first Bézier control point

x2:float

the X coordinate of the second Bézier control point

y2:float

the Y coordinate of the second Bézier control point

x3:float

the X coordinate of the final end point

y3:float

the Y coordinate of the final end point

Annotations
@Override
Exceptions
IOException:
if the curve could not be drawn
drawImageback to summary
public void drawImage(PDImage pdImage) throws IOException

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

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

Draw the image.

Parameters
pdImage:PDImage

The image to draw.

Annotations
@Override
Exceptions
IOException:
if the image could not be drawn
endPathback to summary
public void endPath() throws IOException

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

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

Ends the current path without filling or stroking it. The clipping path is updated here.

Annotations
@Override
Exceptions
IOException:
if the current path could not be ended
fillAndStrokePathback to summary
public void fillAndStrokePath(int windingRule) throws IOException

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

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

Fills and then strokes the path.

Parameters
windingRule:int

The winding rule this path will use.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled and stroke
fillPathback to summary
public void fillPath(int windingRule) throws IOException

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

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

Fill the path.

Parameters
windingRule:int

The winding rule this path will use.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled
getCurrentPointback to summary
public Point2D getCurrentPoint() throws IOException

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

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

Returns the current point of the current path.

Returns:Point2D

the current point or null

Annotations
@Override
Exceptions
IOException:
if the something went wrong when providing the current point
lineToback to summary
public void lineTo(float x, float y) throws IOException

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

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

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

Parameters
x:float

the X-coordinate of the ending-point of the line to be drawn

y:float

the Y-coordinate of the ending-point of the line to be drawn

Annotations
@Override
Exceptions
IOException:
if the line could not be drawn
mainback to summary
public static void main(String[] args) throws IOException
moveToback to summary
public void moveTo(float x, float y) throws IOException

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

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

Starts a new path at (x,y).

Parameters
x:float

the x-coordinate to move to

y:float

the y-coordinate to move to

Annotations
@Override
Exceptions
IOException:
if the something went wrong when moving to the given coordinate
runback to summary
public void run() throws IOException

Runs the engine on the current page.

Exceptions
IOException:
If there is an IO error while drawing the page.
shadingFillback to summary
public void shadingFill(COSName shadingName) throws IOException

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

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

Fill with Shading.

Parameters
shadingName:COSName

The name of the Shading Dictionary to use for this fill instruction.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled using the given shading
showGlyphback to summary
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException

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

Overridden from PDFStreamEngine.

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

showTextStringback to summary
public void showTextString(byte[] string) throws IOException

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showTextString.

Overridden from PDFStreamEngine.

Parameters
string:byte[]

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

the encoded text

Annotations
@Override
Exceptions
IOException:

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

if there was an error showing the text

showTextStringsback to summary
public void showTextStrings(COSArray array) throws IOException

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showTextStrings.

Overridden from PDFStreamEngine.

Parameters
array:COSArray

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

array of encoded text strings and adjustments

Annotations
@Override
Exceptions
IOException:

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

if there was an error showing the text

strokePathback to summary
public void strokePath() throws IOException

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

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

Stroke the path.

Annotations
@Override
Exceptions
IOException:
If there is an IO error while stroking the path.