Skip to content

Preview a file

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

Renders a template sent as a file with sample data and draws one page as a PNG, as POST /v1/templates/{id}/preview does for a stored one, without storing it. Needs no store. The page count is in X-Page-Count.

Media typemultipart/form-data

The form POST /v1/templates/preview takes: the fields of [PreviewForm], and the template as a file.

object
ctx

Visible as ctx, as JSON text.

data

Sample data the template sees as its root, as JSON text.

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
template
required

The template: Office, text, HTML or a PDF form.

string format: binary
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, has no template file, 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'"
}

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'"
}

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'"
}