A Rectangle, Filled or Outlined

Place a rectangle: a coloured band behind a heading, a frame around an area, or both, with the stroke you choose.

See It in a Real PDF

A Minimal PDF

Two identical pages that draw the structure of an invoice with lines and rectangles, without a word of text: the file is about a dozen kilobytes and embeds no font.

Open the PDF The Whole Example

Also shown in: Breaking a Paragraph up, and Aligning It · Breaking an Overlong Word · Soft Hyphens and No-Break Spaces

Summary

The simplest brick there is: four corners, and the choice of what goes inside them. Filled, it makes the grey band behind a section heading or the coloured cell of a table; outlined alone, it marks out a photograph, or an area meant to be cut. When you ask for both, the fill goes down first, so the outline stays visible over it.

Technically

Asked for with "type": "rect"

A rect is a closed path whose four points you are spared: one re operator, then the same painting keys as a free path, the same clips, the same graphics state, the same placement. Its corners take expressions, which gives a band hugging the margins of a page whose width is unknown when the request is written. The fill takes a declared gradient, which makes it the usual carrier of a graded background. Drawing order follows item order: a rectangle placed after a text covers it.

Request Schema

Required key: rect, an object of llx, lly, urx, ury, each a number or an expression. Optional: fill, a colour or {"shading": "name"}; stroke, an object with a required width plus color, dash, cap and join; clip, an object with a required segments and a rule (nonzero by default, even_odd); graphics_state, the name of a declared graphics state; pages, an array of one-based integers, default empty; transform, six numbers; rotate, degrees counter-clockwise about the centre of the rectangle; layer, the name of a declared layer. Cross refusals: transform together with rotate; a clip whose segments are empty. A rectangle takes fill, stroke, or both. fill_rule, nonzero by default or even_odd, says which side of the shape the fill counts as inside: even_odd leaves a subpath drawn inside another empty, so a disc inside a disc fills as a ring, and naming it without a fill is refused. stroke also takes miter_limit, how far a miter corner may run out before it is cut off square, as a ratio of the corner's length to the line's width, 10 by default.

A Whole Request That Creates a PDF

{
  "items": [
    {
      "type": "rect",
      "rect": {"llx": 72, "lly": 700, "urx": 523, "ury": 740},
      "fill": [0.85, 0.89, 0.95],
      "stroke": {"width": 1.0, "color": [0.11, 0.31, 0.55]}
    }
  ]
}

The line that sends it, in three languages

Shapes

A Free Path: Lines, Curves and Filled Shapes A Straight Line between Two Points A Drawing Declared Once and Placed as Often as Wanted

Where to Go Next

Every JSON key of a request, in one page The other twenty-two things you can draw

See the Prices See the Examples