Developer Documentation
Feedback

Rendering an image or PDF

Basics

Rendering an image or PDF is as simple as sending a POST request to the /render endpoint. Pass your API key as the Authorization header. The request body may differ slightly depending on the type of document you want to render. To generate a PDF, pass 'pdf' as the type property, otherwise use 'png' or 'jpeg' for images. Renders are saved directly to AWS S3 and their public URLs are returned as JSON by the API.

MethodURLCreditsDescription
POSThttps://api.tailrender.com/render1Render an image or PDF

Request body

In the POST request body, you can pass the following:

NameTypedefaultDescription
htmlstring*requiredHTML content of the render
typepdf, png, html, jpegpngType of render
formatletter, legal, tabloid, ledger, a0, a1, a2, a3, a4, a5, a6letterFormat size of the PDF document
widthnumber*required if imageWidth of the image
heightnumber*required if imageHeight of the image
transparentbooleanfalseWhether to generate the image with a transparent background
qualitynumber1Scale of the image. If quality is 2 and the image dimensions are 100x100, the rendered image will be 200x200
tailwindConfigobject{ "theme": { "extend": {} } }See TailwindCSS config documentation . Note plugins are disabled.
propsobjectnullProperties to pass to the render
cssstring@tailwind base;
@tailwind components;
@tailwind utilities
Tailwind base classes as well as any custom CSS
webhookUrlstring''When specified, the API will deliver a POST request to this endpoint with the render result payload

Example request

javascript
const body = {
type: 'png',
width: 400,
height: 350,
transparent: true,
html: "<div class='p-4 text-center text-gray-800 text-lg rounded-md bg-white'>{{ title }}</div>",
props: {
title: 'A super basic card with Tailwind CSS'
}
};
const response = await fetch('https://api.tailrender.com/render', {
method: 'POST',
headers: {
Authorization: "{{ YOUR_API_KEY }}",
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
});
const json = response.json();

Passing properties

The template API supports passing properties to the render. Properties are passed to the template as a JSON object. Use the props field to pass properties to the render. The API uses Mustache under the hood to render the template. See the Mustache documentation for more information on how to use Mustache syntax. Additionally, any props passed to the render will appear on the render result object. This is useful when attempting to associate render webhooks received from the API.

Webhooks

Instead of synchronous generation, you can choose to have your render result delivered via webhook instead. To use webhook delivery, specify the webhook URL using the webhookUrl field. The API will respond with a 202 Accepted status code when your render request is received. When the render is complete, the API will deliver a POST request to the webhook URL with the render result payload. Three attempts will be made to deliver the webhook, each with a delay of 15 seconds between requests, before declaring the result undeliverable.

Supplemental CSS

You can pass supplemental CSS to the render by passing a css property. If you pass a css property, you must include the base TailwindCSS utility classes along with any custom CSS you want to use. For example, if you want to use the b-green CSS class, you must include the following:

css
@tailwind base;
@tailwind components;
@tailwind utilities
.b-green {
@apply text-green-500 font-bold;
}

Failing to specify the base TailwindCSS utility classes will prevent the API from compiling the CSS properly.

Tailwind CSS Config

The tailwindConfig property is an object that contains the TailwindCSS configuration. The default configuration is included in as a part of every request. Plugins are currently unsupported by the API, although we do support the official TailwindCSS plugins. See the TailwindCSS documentation for more information.

Example response body

json
{
"id": "r5mT9aAuUhstaJYBNGcJ",
"templateName": "resume-template",
"status": "COMPLETED",
"result": {
"pdfUrl": "https://tailrender-api.s3.amazonaws.com/pdf/r5mT9aAuUhstaJYBNGcJ.pdf",
"url": "https://tailrender-api.s3.amazonaws.com/pdf/r5mT9aAuUhstaJYBNGcJ.pdf"
},
"props": {
"phone": "(555) 234-2344",
"email": "jane.smith@gmail.com"
}
}

Errors

You may receive an error while attempting to render your file. Errors while generating files are quite rare, however, if the error persists, please contact support.

A file generation error might look like the following:

json
{
"id": "lhXcGjxf63vq27odmqCb",
"status": "ERROR",
"error": "An unknown error occurred while attempting to generate this file."
}