A block of text placed on the page
Set text inside a chosen rectangle, with its font, size and colour, and give one word in the middle of a sentence a style of its own.
Summary
As if the frame had been drawn in pencil: you say what goes inside, and the text arranges itself there, line after line, to the last word. On the way, a word can be picked out — bigger, bold, underlined, another colour — without breaking the sentence around it. This is the piece used everywhere, from the heading of an invoice to the small print at the foot of the page.
Technically
Asked for with
"type": "text"
A text item lays a block of text inside a rectangle given in points, in page coordinates: the origin sits at the bottom left and the vertical axis goes up. The runs go into the page content stream between BT and ET, in the font resources the request declared. The content is a list of runs: a plain string takes the block's style, while an object overrides, for itself alone, the font, the size, the leading, the colour, the rules (underline, strikethrough, overline) or the stroke drawn round its letters. A run can also ask the server for the moment of rendering, formatted with a strftime pattern in the named time zone. The text accepts the pagination placeholders, resolved once the last page exists, which gives a footer reading "page 3 of 12" written once for the whole document.
Request schema
Required keys: rect, an object of four coordinates llx, lly, urx, ury, each a number or a quoted expression (+ - * / ( ), variables {page_width}, {page_height}, {current_page}, {total_pages}, {llx}, {lly}, {urx}, {ury}, maximum depth 100); content, an array of runs; font, a string naming a font the request declared (standard_fonts, fonts, type1_fonts, type3_fonts, font_chains, font_variants); font_size, a number of points. A run takes three shapes: a bare string; an object {"text": …} with optional font, font_size, leading, underline, strikethrough, overline, color and outline, each holding for that run alone; an object {"date": "strftime pattern"} with an optional zone (an IANA name; absent, the moment is stamped in universal time). Optional keys on the block: align (left by default, right, center, justify); overlong (overflow by default, an over-wide word runs past the edge; break cuts it); leading (default 1.2 × font_size); break_after, the characters a line may break after (by default breaks happen at spaces and soft hyphens); underline, strikethrough, overline, booleans at false; color (default black); outline, an object of width, a required number of points, color (default black) and filled (default false), the stroke drawn round the letters of every run that names none of its own, hollow unless filled draws them solid as well; shadow, an object whose dx, dy and color are all required; pages, an array of one-based integers, default empty, meaning every page; id, a string another item refers to; relative_to, an object of id, edge (top or bottom), offset and an optional part (default: the last part laid); transform, six numbers; rotate, degrees counter-clockwise about the centre of the rectangle; layer, the name of a declared layer; clip, an object with a required segments and a rule (nonzero by default, even_odd), the shape the block is seen through; graphics_state, the name of a declared state the whole block, shadow included, is drawn under. Cross refusals: transform together with rotate; a clip whose segments are empty.
A whole request that creates a PDF
{
"standard_fonts": [{"name": "sans", "face": "helvetica"}],
"items": [
{
"type": "text",
"rect": {"llx": 72, "lly": 740, "urx": 523, "ury": 780},
"content": ["Invoice 1964413", {"text": " — paid", "color": [0.1, 0.45, 0.25]}],
"font": "sans",
"font_size": 16,
"outline": {"width": 0.4, "color": [0.1, 0.45, 0.25], "filled": true}
}
]
}
Text
Text in paragraphs, with indents and tab stops A stamp laid across the page A line of words set along a path Blocks laid one under the other, page after page
Where to go next
Every JSON key of a request, in one page The other twenty-two things you can draw