Package net.codecrete.qrbill.canvas
Class PDFCanvas
- java.lang.Object
-
- net.codecrete.qrbill.canvas.AbstractCanvas
-
- net.codecrete.qrbill.canvas.PDFCanvas
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Canvas
public class PDFCanvas extends AbstractCanvas
PDF graphics generator
-
-
Field Summary
-
Fields inherited from class net.codecrete.qrbill.canvas.AbstractCanvas
MM_TO_PT
-
-
Constructor Summary
Constructors Constructor Description PDFCanvas()Creates a new instance of the graphics generator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRectangle(double x, double y, double width, double height)Adds a rectangle to the pathvoidclose()voidfillPath(int color)Fills the current path and ends itbyte[]getResult()Returns the generated graphics as a byte arrayvoidlineTo(double x, double y)Adds a line segment to the open path from the previous point to the speicifed position.voidmoveTo(double x, double y)Moves the current point of the open path to the specified position.voidputText(java.lang.String text, double x, double y, int fontSize, boolean isBold)Adds text to the graphics.voidputTextLines(java.lang.String[] lines, double x, double y, int fontSize, double leading)Adds several lines of text to the graphics.voidsetTransformation(double translateX, double translateY, double scale)Sets a translation and a scale factor for the subsequent operationsvoidsetupPage(double width, double height)Sets up the pagevoidstartPath()Starts a path that can be filled or strokedvoidstrokePath(double strokeWidth, int color)Strokes the current path and ends it
-
-
-
Method Detail
-
setupPage
public void setupPage(double width, double height) throws java.io.IOExceptionDescription copied from interface:CanvasSets up the pageThe page (and graphics context) is not valid until this method has been called.
- Parameters:
width- width of page (in mm)height- height of page (in mm)- Throws:
java.io.IOException- thrown if graphics cannot be generated
-
setTransformation
public void setTransformation(double translateX, double translateY, double scale) throws java.io.IOExceptionDescription copied from interface:CanvasSets a translation and a scale factor for the subsequent operationsBefore a new translation is applied, the coordinate system is reset to it's original state after page setup (see
setupPage).- Parameters:
translateX- translation in x direction (in mm)translateY- translation in y direction (in mm)scale- scale fator (1.0 = no scaling)- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
putText
public void putText(java.lang.String text, double x, double y, int fontSize, boolean isBold) throws java.io.IOExceptionDescription copied from interface:CanvasAdds text to the graphics.The text position refers to the left most point on the text's baseline.
- Parameters:
text- the textx- x position of the text's start (in mm)y- y position of the text's top (in mm)fontSize- the font size (in pt)isBold- indicates if the text is in bold or regular weight- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
putTextLines
public void putTextLines(java.lang.String[] lines, double x, double y, int fontSize, double leading) throws java.io.IOExceptionDescription copied from interface:CanvasAdds several lines of text to the graphics.The text position refers to the left most point on the baseline of the first text line. Additional lines then follow below.
- Specified by:
putTextLinesin interfaceCanvas- Overrides:
putTextLinesin classAbstractCanvas- Parameters:
lines- the text linesx- x position of the text's start (in mm)y- y position of the text's top (in mm)fontSize- the font size (in pt)leading- additional vertical space between text lines (in mm)- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
startPath
public void startPath()
Description copied from interface:CanvasStarts a path that can be filled or stroked
-
moveTo
public void moveTo(double x, double y) throws java.io.IOExceptionDescription copied from interface:CanvasMoves the current point of the open path to the specified position.- Parameters:
x- x-coordinate of positiony- y-coordinate of position- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
lineTo
public void lineTo(double x, double y) throws java.io.IOExceptionDescription copied from interface:CanvasAdds a line segment to the open path from the previous point to the speicifed position.- Parameters:
x- x-coordinate of positiony- y-coordinate of position- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
addRectangle
public void addRectangle(double x, double y, double width, double height) throws java.io.IOExceptionDescription copied from interface:CanvasAdds a rectangle to the path- Parameters:
x- the rectangle's left position (in mm)y- the rectangle's top position (in mm)width- the rectangle's width (in mm)height- rectangle's height (in mm)- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
fillPath
public void fillPath(int color) throws java.io.IOExceptionDescription copied from interface:CanvasFills the current path and ends it- Parameters:
color- the fill color (expressed similar to HTML, e.g. 0xffffff for white)- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
strokePath
public void strokePath(double strokeWidth, int color) throws java.io.IOExceptionDescription copied from interface:CanvasStrokes the current path and ends it- Parameters:
strokeWidth- the stroke width (in pt)color- the stroke color (expressed similar to HTML, e.g. 0xffffff for white)- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
getResult
public byte[] getResult() throws java.io.IOExceptionDescription copied from interface:CanvasReturns the generated graphics as a byte arrayAfter this method was called, the page is no longer valid.
- Returns:
- the byte array
- Throws:
java.io.IOException- thrown if the graphics cannot be generated
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
-