Class CustomGraphicsStreamEngine
- java.lang.Object
-
- org.apache.pdfbox.contentstream.PDFStreamEngine
-
- org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine
-
- org.apache.pdfbox.examples.rendering.CustomGraphicsStreamEngine
-
public class CustomGraphicsStreamEngine extends PDFGraphicsStreamEngine
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
PDFStreamEnginefor further methods which may be overridden.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCustomGraphicsStreamEngine(PDPage page)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendRectangle(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)Append a rectangle to the current path.voidclip(int 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.voidendPath()Ends the current path without filling or stroking it.voidfillAndStrokePath(int windingRule)Fills and then strokes the path.voidfillPath(int windingRule)Fill the path.java.awt.geom.Point2DgetCurrentPoint()Returns the current point of the current path.voidlineTo(float x, float y)Draws a line from the current point to (x,y).static voidmain(java.lang.String[] args)voidmoveTo(float x, float y)Starts a new path at (x,y).voidrun()Runs the engine on the current page.voidshadingFill(COSName shadingName)Fill with Shading.protected voidshowGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement)Overridden from PDFStreamEngine.voidshowTextString(byte[] string)Overridden from PDFStreamEngine.voidshowTextStrings(COSArray array)Overridden from PDFStreamEngine.voidstrokePath()Stroke the path.-
Methods inherited from class org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine
getPage
-
Methods inherited from class org.apache.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, beginMarkedContentSequence, beginText, decreaseLevel, endMarkedContentSequence, endText, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, isShouldProcessColorOperators, markedContentPoint, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showAnnotation, showFontGlyph, showForm, showText, showTransparencyGroup, showType3Glyph, transformedPoint, transformWidth, unsupportedOperator
-
-
-
-
Constructor Detail
-
CustomGraphicsStreamEngine
protected CustomGraphicsStreamEngine(PDPage page)
Constructor.- Parameters:
page- PDF Page
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.io.IOException- Throws:
java.io.IOException
-
run
public void run() throws java.io.IOExceptionRuns the engine on the current page.- Throws:
java.io.IOException- If there is an IO error while drawing the page.
-
appendRectangle
public void appendRectangle(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3) throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineAppend a rectangle to the current path.- Specified by:
appendRectanglein classPDFGraphicsStreamEngine- Parameters:
p0- starting coordinate of the rectanglep1- second coordinate of the rectanglep2- third coordinate of the rectanglep3- last coordinate of the rectangle- Throws:
java.io.IOException- if the rectangle could not be appended
-
drawImage
public void drawImage(PDImage pdImage) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngineDraw the image.- Specified by:
drawImagein classPDFGraphicsStreamEngine- Parameters:
pdImage- The image to draw.- Throws:
java.io.IOException- if the image could not be drawn
-
clip
public void clip(int windingRule) throws java.io.IOExceptionDescription 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.- Throws:
java.io.IOException- if the clipping path could not be modified
-
moveTo
public void moveTo(float x, float y) throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineStarts a new path at (x,y).- Specified by:
moveToin classPDFGraphicsStreamEngine- Parameters:
x- the x-coordinate to move toy- the y-coordinate to move to- Throws:
java.io.IOException- if the something went wrong when moving to the given coordinate
-
lineTo
public void lineTo(float x, float y) throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineDraws a line from the current point to (x,y).- Specified by:
lineToin classPDFGraphicsStreamEngine- Parameters:
x- the X-coordinate of the ending-point of the line to be drawny- the Y-coordinate of the ending-point of the line to be drawn- Throws:
java.io.IOException- if the line could not be drawn
-
curveTo
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws java.io.IOExceptionDescription 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- the X coordinate of the first Bézier control pointy1- the Y coordinate of the first Bézier control pointx2- the X coordinate of the second Bézier control pointy2- the Y coordinate of the second Bézier control pointx3- the X coordinate of the final end pointy3- the Y coordinate of the final end point- Throws:
java.io.IOException- if the curve could not be drawn
-
getCurrentPoint
public java.awt.geom.Point2D getCurrentPoint() throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineReturns the current point of the current path.- Specified by:
getCurrentPointin classPDFGraphicsStreamEngine- Returns:
- the current point or null
- Throws:
java.io.IOException- if the something went wrong when providing the current point
-
closePath
public void closePath() throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineCloses the current path.- Specified by:
closePathin classPDFGraphicsStreamEngine- Throws:
java.io.IOException- if the current path could not be closed
-
endPath
public void endPath() throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineEnds the current path without filling or stroking it. The clipping path is updated here.- Specified by:
endPathin classPDFGraphicsStreamEngine- Throws:
java.io.IOException- if the current path could not be ended
-
strokePath
public void strokePath() throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineStroke the path.- Specified by:
strokePathin classPDFGraphicsStreamEngine- Throws:
java.io.IOException- If there is an IO error while stroking the path.
-
fillPath
public void fillPath(int windingRule) throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineFill the path.- Specified by:
fillPathin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule this path will use.- Throws:
java.io.IOException- if the path could not be filled
-
fillAndStrokePath
public void fillAndStrokePath(int windingRule) throws java.io.IOExceptionDescription copied from class:PDFGraphicsStreamEngineFills and then strokes the path.- Specified by:
fillAndStrokePathin classPDFGraphicsStreamEngine- Parameters:
windingRule- The winding rule this path will use.- Throws:
java.io.IOException- if the path could not be filled and stroke
-
shadingFill
public void shadingFill(COSName shadingName) throws java.io.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:
java.io.IOException- if the path could not be filled using the given shading
-
showTextString
public void showTextString(byte[] string) throws java.io.IOExceptionOverridden from PDFStreamEngine.- Overrides:
showTextStringin classPDFStreamEngine- Parameters:
string- the encoded text- Throws:
java.io.IOException- if there was an error showing the text
-
showTextStrings
public void showTextStrings(COSArray array) throws java.io.IOException
Overridden from PDFStreamEngine.- Overrides:
showTextStringsin classPDFStreamEngine- Parameters:
array- array of encoded text strings and adjustments- Throws:
java.io.IOException- if there was an error showing the text
-
showGlyph
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws java.io.IOException
Overridden from PDFStreamEngine.- Overrides:
showGlyphin 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:
java.io.IOException- if the glyph cannot be processed
-
-