Colors, Shapes, And Vectors
Recipe accepts hexadecimal colors, component arrays, percentage colors, and
named colors registered with chroma.
pdfDoc
.createPage("letter")
.chroma("brandBlue", "#0066cc")
.rectangle(72, 72, 180, 80, {
fill: "brandBlue",
stroke: "#000000",
lineWidth: 1,
})
.ellipse(360, 112, 60, 35, { fill: [255, 0, 0] })
.line(
[
[72, 200],
[250, 200],
],
{ stroke: "#008000", lineWidth: 2 },
)
.endPage()
.endPDF();
lineWidth(width) remains available as a shorthand for
lineStyle({ width }).
Use moveTo and lineTo for connected paths, line and polygon for point
arrays, and circle, rectangle, ellipse, arc, pie, n_gon, star,
triangle, and arrow for shapes. pie closes an arc back to its center, so
it can be filled as a wedge. Shape options support fill, stroke, opacity,
rotation, rotation origin, skew, dash, and line properties. See
Create A Pie Chart for a filled-wedge chart
example.
For circle, ellipse, rectangle, arc, and pie, positive requested
dimensions that are each at least the line width include the complete stroke:
Recipe insets the stroke centerline by half its width so the outer edge stays
inside those bounds. The fill still uses the full requested dimensions. Smaller
or negative geometry follows native PDF path behavior and is not guaranteed to
stay inside the requested bounds. Polygon strokes remain centered on their path.
Use opacity(value) to set both fill and stroke alpha for subsequent drawing;
value must be a finite number from 0 (transparent) through 1 (opaque).
It remains active for later vector drawing; call opacity(1) to restore opaque
output.
Use lineStyle() to set the PDF stroke style for subsequent drawing on the
current page context. It accepts width (or lineWidth), numeric PDF cap
and join values, miterLimit, dash, and dashPhase. Omitted properties
leave the existing style unchanged: