Services
PDF Generation
Render HTML zu PDF. Charts sind inline via <chart> möglich.
Route
- Methode: POST
- URL: /api/pdf/generate
- Auth:
x-api-key
für Public‑Aufrufe oder intern (Cookie)
Request
- templateId: string (optional; alternativ zu
html
) - html: string (optional; alternativ zu
templateId
) - variables: object|string (optional; für Template‑Variablen)
- format: string (z. B. A4)
- landscape: boolean
- filename: string
- headerTemplate, footerTemplate: string (optional)
- marginTop|Right|Bottom|Left: string (z. B. 12mm)
Endpoint
/api/pdf/generate (POST)
{
"html": "<!doctype html><html><head><meta charset=\"utf-8\"/></head><body>\n<h1>{{title}}</h1>\n<p>{{subtitle}}</p>\n<chart type=\"line\" width=\"800\" height=\"320\"\n data=\"{{jsonattr chart.data}}\" options=\"{{jsonattr chart.options}}\" ></chart>\n</body></html>",
"variables": {
"title": "Monthly Revenue",
"subtitle": "January – June",
"chart": {
"data": {
"labels": [
"Jan",
"Feb"
],
"datasets": [
{
"label": "Umsatz",
"data": [
12,
19
]
}
]
},
"options": {
"responsive": false
}
}
},
"format": "A4",
"landscape": false,
"filename": "report.pdf"
}
curl -X POST "https://dev.nuvisphere.de/api/pdf/generate" \
-H "Content-Type: application/json" \
-H "x-api-key: API_KEY"
-d '{
"html": "<!doctype html><html><head><meta charset=\"utf-8\"/></head><body>\n<h1>{{title}}</h1>\n<p>{{subtitle}}</p>\n<chart type=\"line\" width=\"800\" height=\"320\"\n data=\"{{jsonattr chart.data}}\" options=\"{{jsonattr chart.options}}\" ></chart>\n</body></html>",
"variables": {
"title": "Monthly Revenue",
"subtitle": "January – June",
"chart": {
"data": {
"labels": [
"Jan",
"Feb"
],
"datasets": [
{
"label": "Umsatz",
"data": [
12,
19
]
}
]
},
"options": {
"responsive": false
}
}
},
"format": "A4",
"landscape": false,
"filename": "report.pdf"
}'
// server-side (Node/Next.js)
const res = await fetch("https://dev.nuvisphere.de/api/pdf/generate", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.MAILER_API_KEY!,
},
body: JSON.stringify({
"html": "<!doctype html><html><head><meta charset=\"utf-8\"/></head><body>\n<h1>{{title}}</h1>\n<p>{{subtitle}}</p>\n<chart type=\"line\" width=\"800\" height=\"320\"\n data=\"{{jsonattr chart.data}}\" options=\"{{jsonattr chart.options}}\" ></chart>\n</body></html>",
"variables": {
"title": "Monthly Revenue",
"subtitle": "January – June",
"chart": {
"data": {
"labels": [
"Jan",
"Feb"
],
"datasets": [
{
"label": "Umsatz",
"data": [
12,
19
]
}
]
},
"options": {
"responsive": false
}
}
},
"format": "A4",
"landscape": false,
"filename": "report.pdf"
}),
});
if (!res.ok) throw new Error(`Request failed ${res.status}`);
const json = await res.json();
- API Key niemals im Browser verwenden – nur serverseitig (z. B.
process.env.MAILER_API_KEY
). - Lässt du optionale Felder weg, nutzt die API ggf. Template-/Defaultwerte.
Template & Variablen
<!doctype html><html><head><meta charset="utf-8"/></head><body>
<h1>{{title}}</h1>
<p>{{subtitle}}</p>
<chart type="line" width="800" height="320"
data="{{jsonattr chart.data}}" options="{{jsonattr chart.options}}" ></chart>
</body></html>
{
"title": "Monthly Revenue",
"subtitle": "January – June",
"chart": {
"data": {
"labels": [
"Jan",
"Feb"
],
"datasets": [
{
"label": "Umsatz",
"data": [
12,
19
]
}
]
},
"options": {
"responsive": false
}
}
}
Tipp: Für JSON in HTML‑Attributen {{jsonattr ...}}
nutzen.