Skip to content

Preview a template

POST
/v1/templates/{id}/preview
curl -H "X-Api-Key: $KEY" -F 'data=<invoice.json' -F width=400 \
"http://localhost:9027/v1/templates/$ID/preview" -o page.png

Renders a stored template with sample data and draws one page as a PNG, for checking a template without opening the document. Office templates convert with LibreOffice, HTML with its HTML engine, and PDF forms are filled; poppler’s pdftoppm draws the page. The page count is in X-Page-Count.

id
required
string

The template’s id, or an alias as name or name@version

The fields POST /v1/templates/{id}/preview accepts, as JSON or as a multipart form.

object
ctx

Visible as ctx.

data

Sample data the template sees as its root.

dpi

Draw at this resolution, from 18 to 300, as large as the page is. An image may not pass 4000 pixels on a side.

integer | null format: int32
htmlEngine

What turns HTML into PDF: fulgur (default) or libreoffice.

string | null
page

The page to draw, from 1. Default 1.

integer | null format: int32
width

The image’s width in pixels, from 16 to 2000; the height follows the page. Default 800. Send this or dpi.

integer | null format: int32

The page as a PNG

Media typeimage/png

The file, as bytes.

string format: binary
X-Page-Count
integer format: int32

How many pages the rendered document has

The request is wrong, or the page does not exist

Media typeapplication/json

The JSON body of every error response.

object
error
required

A stable, machine-readable kind.

string
message
required

What went wrong, for a person.

string

Example

{
"error": "invalid_request",
"message": "unknown step 'teleport'"
}

This caller has no such template

Media typeapplication/json

The JSON body of every error response.

object
error
required

A stable, machine-readable kind.

string
message
required

What went wrong, for a person.

string

Example

{
"error": "invalid_request",
"message": "unknown step 'teleport'"
}

The template failed to render

Media typeapplication/json

The JSON body of every error response.

object
error
required

A stable, machine-readable kind.

string
message
required

What went wrong, for a person.

string

Example

{
"error": "invalid_request",
"message": "unknown step 'teleport'"
}

RUSTICDOC_STORE is not set

Media typeapplication/json

The JSON body of every error response.

object
error
required

A stable, machine-readable kind.

string
message
required

What went wrong, for a person.

string

Example

{
"error": "invalid_request",
"message": "unknown step 'teleport'"
}

Pdftoppm or LibreOffice is unavailable, or the request timed out

Media typeapplication/json

The JSON body of every error response.

object
error
required

A stable, machine-readable kind.

string
message
required

What went wrong, for a person.

string

Example

{
"error": "invalid_request",
"message": "unknown step 'teleport'"
}