A Page of a Supplied PDF, Placed on the Page
Take one page of a PDF sent with the request and place it in a frame, at its own proportions, among the other items.
See It in a Real PDF
An Invoice Laid on a Letterhead Template
An invoice laid over a letterhead supplied as a PDF file.
Open the PDF The Whole Example
Also shown in: A Template Whose Regions Are Filled by Name
Summary
You already have a warranty slip, a plan or a receipt as a PDF. Rather than making it again, you send it as it is. The page grows until it meets the nearest edge of the frame and centres in what is left, unsquashed. Around it you carry on writing, drawing and placing tables as usual. When the page has named spaces to fill, such as where the address goes or where the logo goes, you send the words or the picture under that name, and each lands in its space wherever the page lands.
Technically
Asked for with
"type": "pdf_page"
The source PDF's bytes travel with the request, in a supplied part; the pdf key repeats that name, from the same pool the templates come from, so one supplied file serves both as a page background and as a placed item. The page number counts from 1. That page is copied, with the resources it uses, into a form XObject, then painted inside the frame: it keeps its proportions, scaled until it meets the frame's width or height, then centred in the rest. Unlike a template, which lines the whole page under the content, this item is one element among the others, placed in a box, and so combines with text beside it.
Request Schema
Required keys: pdf, a string naming the supplied part; rect. Optional: page, a one-based integer, default 1; pages, an array of one-based integers, default empty for every page of the finished document; transform, six numbers; rotate, degrees counter-clockwise about the centre of the rectangle; layer, the name of a declared layer. Cross refusal: transform together with rotate. The imported page always keeps its proportions: the images' fit key has no counterpart here. from_defaults, the name of a declared graphics state stated initial, is the state the page is drawn from: it is set, then black fill and stroke, a one-point solid line with butt caps, mitred joins and a mitre limit of ten, and the text state at rest, so that a page relying on the values a page starts with draws in them rather than in whatever the page it lands on last set; absent, the page draws in the state in force where it is placed. keep_layers, a boolean at false, true making the layers the page's own document marks it with rows of this document's layers panel, under the names and in the states that document gave them. own_runs, the label the structure tree claims the runs the page's own document marked inside it by, through a node's imported_runs, so a tagged page brought in keeps its paragraphs, headings and figures in the tree. fill, an object keyed by the names of the regions the page's own file marks, as page_regions marks them, each filled where it lands: text with content, and font, font_size, color and align over the region's own; image naming a supplied picture; drawing naming a declared drawing or one of svg_drawings; page naming a page of a supplied PDF by pdf and page, which takes a fill and an unfilled of its own. The last three take fit and anchor. unfilled, sample by default: every region of text the request leaves unfilled shows its sample; empty leaves it blank. Each fill takes tag and mark, as an item does: without them, what it draws is furniture a screen reader passes over; with them, a numbered run the structure tree claims. Refused: a name no region holds, a region of another kind, any fill on a page whose file marks no regions, one of tag and mark without the other.
A Whole Request That Creates a PDF
{
"items": [
{
"type": "pdf_page",
"pdf": "label.pdf",
"page": 1,
"boundary": "crop",
"clip": "crop",
"rect": {"llx": 72, "lly": 480, "urx": 523, "ury": 780},
"fill": {
"recipient": {"text": {"content": "Anna Keller\nSeestrasse 12\n8002 Zürich"}}
},
"unfilled": "sample"
}
]
}
Pictures and imported pages
Where to Go Next
Every JSON key of a request, in one page The other twenty-two things you can draw