Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class PdfCanvas
- Object
- PdfCanvas
Draws the content of one PdfPage.
Coordinates are in points (1/72 inch) with the origin at the top
left of the page and y growing downwards, as in Codename One’s
Graphics; text is placed by its baseline. Shapes are built as a path
and then filled, stroked or used as a clip:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.addPage(PdfPageSize.A4);
PdfCanvas c = page.getCanvas();
c.setFillColor(0x1565c0);
c.fillRect(36, 36, page.getWidth() - 72, 40);
c.setFillColor(0xffffff);
c.setFont(PdfFont.HELVETICA_BOLD, 18);
c.drawText("Invoice 2031", 48, 62);
c.setStrokeColor(0x999999);
c.setLineWidth(0.5f);
c.drawLine(36, 90, page.getWidth() - 36, 90);save() and restore() bracket changes to the color, line style,
transform, clip and font.
Fields
public static final int CAP_BUTT = 0 | Butt line cap: the stroke ends at the end point. |
public static final int CAP_ROUND = 1 | Round line cap. |
public static final int CAP_SQUARE = 2 | Square line cap: the stroke extends half its width past the end. |
public static final int JOIN_MITER = 0 | Mitered line join. |
public static final int JOIN_ROUND = 1 | Round line join. |
public static final int JOIN_BEVEL = 2 | Beveled line join. |
Methods
Inherited methods
Field details
CAP_BUTT
public static final int CAP_BUTT = 0CAP_ROUND
public static final int CAP_ROUND = 1CAP_SQUARE
public static final int CAP_SQUARE = 2JOIN_MITER
public static final int JOIN_MITER = 0JOIN_ROUND
public static final int JOIN_ROUND = 1JOIN_BEVEL
public static final int JOIN_BEVEL = 2Method details
save
public PdfCanvas save()restore
public PdfCanvas restore()save().translate
public PdfCanvas translate(float dx, float dy)dx, dy.scale
public PdfCanvas scale(float sx, float sy)sx, sy around the origin.rotate
public PdfCanvas rotate(double radians)radians clockwise around the origin.transform
public PdfCanvas transform(float a, float b, float c, float d, float e, float f)[a b c d e f] with the current transform:
a point (x, y) maps to (a*x + c*y + e, b*x + d*y + f).setFillColor
public PdfCanvas setFillColor(int rgb)0xRRGGBB.setStrokeColor
public PdfCanvas setStrokeColor(int rgb)0xRRGGBB.setFillAlpha
public PdfCanvas setFillAlpha(float alpha)setStrokeAlpha
public PdfCanvas setStrokeAlpha(float alpha)setLineWidth
public PdfCanvas setLineWidth(float width)setLineCap
public PdfCanvas setLineCap(int cap)CAP_ constants.setLineJoin
public PdfCanvas setLineJoin(int join)JOIN_ constants.setMiterLimit
public PdfCanvas setMiterLimit(float limit)setDash
public PdfCanvas setDash(float[] pattern, float phase)phase points into the pattern. Null or empty draws solid lines.moveTo
public PdfCanvas moveTo(float x, float y)(x, y).lineTo
public PdfCanvas lineTo(float x, float y)(x, y).curveTo
public PdfCanvas curveTo(float x1, float y1, float x2, float y2, float x3, float y3)(x1, y1) and
(x2, y2) to (x3, y3).quadTo
public PdfCanvas quadTo(float cx, float cy, float x, float y)(cx, cy) to
(x, y).closePath
public PdfCanvas closePath()rect
public PdfCanvas rect(float x, float y, float w, float h)roundRect
public PdfCanvas roundRect(float x, float y, float w, float h, float radius)radius points.ellipse
public PdfCanvas ellipse(float x, float y, float w, float h)fill
public PdfCanvas fill()fillEvenOdd
public PdfCanvas fillEvenOdd()stroke
public PdfCanvas stroke()fillAndStroke
public PdfCanvas fillAndStroke()clip
public PdfCanvas clip()clipEvenOdd
public PdfCanvas clipEvenOdd()fillRect
public PdfCanvas fillRect(float x, float y, float w, float h)strokeRect
public PdfCanvas strokeRect(float x, float y, float w, float h)drawLine
public PdfCanvas drawLine(float x1, float y1, float x2, float y2)(x1, y1) to (x2, y2).setFont
public PdfCanvas setFont(PdfFont font, float size)getFont
public PdfFont getFont()setFont(PdfFont, float).getFontSize
public float getFontSize()drawText
public PdfCanvas drawText(String text, float x, float y)Draws text in the current font and fill color with its baseline
starting at (x, y). Line breaks are not interpreted; lay out
several lines with PdfLayout.
Text is given in reading order. Right-to-left scripts (Hebrew, Arabic) are reordered for display by the Unicode bidirectional algorithm, with the direction taken from the first strong character, and Arabic letters are joined, using the font’s own contextual forms when it is a TrueType font that has them.
drawText
public PdfCanvas drawText(String text, float x, float y, int direction)text as drawText(String, float, float) does, in a
paragraph of direction direction, one of the
PdfParagraph.DIRECTION_ constants. The text still starts at x.drawImage
public PdfCanvas drawImage(PdfImage image, float x, float y, float w, float h)image scaled into the rectangle (x, y, w, h).appendRaw
public PdfCanvas appendRaw(String operators)