1. Grab an API key
You can get or generate an API key in your printerz dashboard (opens in a new tab).
2. Get your template id
You can find your template id in your printerz dashboard (opens in a new tab).
3. Render your template
In order to render your template as a PDF you will simply need to hit our API endpoint at
POST - https://api.printerz.dev/templates/{templateId}/render
Each call must be authenticated with an API key in the x-api-key
header.
You can also send variables and options to your template.
Body key | Type | Description |
---|---|---|
variables | Object | An object containing the variables to pass to your template |
options | Object | An object containing the options that will be passed to chromium for rendering the pdf options can be found here (opens in a new tab) |
import { writeFile } from "node:fs/promises"
const options = {
method: 'POST',
headers: { 'x-api-key': 'sk_your_api_key', 'Content-Type': 'application/json' },
body: JSON.stringify({
variables: {
"some": "variables"
},
options: {
"printBackground": true
}
})
};
const templateId = 'your-template-id';
const response = await fetch(`https://api.printerz.dev/templates/${templateId}/render`, options);
if(!response.ok) {
throw new Error(response.statusText);
}
const pdfBuffer = await response.arrayBuffer();
await writeFile('output.pdf', Buffer.from(pdfBuffer));