Skip to content

Render with inline HTML

Send the HTML in the request when you generate it yourself, when it comes from another system, or when you want a one-off document and nothing to maintain in the portal.

Terminal window
curl -X POST https://api.example.com/v1/render \
-H "Authorization: Bearer $RUSTEDF_KEY" \
-H "Content-Type: application/json" \
-d '{
"html": "<h1>Hello {{ name }}</h1><p>{{ total | currency(code=\"USD\") }}</p>",
"data": { "name": "World", "total": "1234.50" },
"locale": "en-US"
}' \
-o hello.pdf

The html field is a template, just like a saved one: {{ }}, {% %} and the formatting filters all work (see Templates). If your HTML is already final, with no placeholders, send it as is and leave data out.

Do not paste data into the HTML string yourself; pass it in data so it is escaped. In Node.js:

const response = await fetch('https://api.example.com/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RUSTEDF_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
html: '<h1>{{ title }}</h1><ul>{% for i in items %}<li>{{ i }}</li>{% endfor %}</ul>',
data: { title: 'Shopping list', items: ['Bread', 'Milk'] },
}),
});
  • Send html or template_id, never both and never neither: that is a 400.
  • Nothing is saved. There is no version and no preview in the portal; the HTML is sent again on every request, and the size limit of your plan applies to it.
  • Images must be uploaded assets (asset:<id>) or data: URLs; see Images.
  • Use /v1/validate with the same body to check the document without using a credit.

When the same layout is generated often, a saved template is easier to keep. The request and response are described in Rendering a PDF.