Integration guide
Node.js HTML to PDF API
Convert HTML templates into PDFs in Node.js with one API request. Ideal for invoices, receipts, statements, and report exports.
Install dependencies
npm install node-fetch
Example request
import fs from "node:fs/promises";
import fetch from "node-fetch";
const apiKey = process.env.HTML2PDF_API_KEY;
const auth = Buffer.from(`${apiKey}:`).toString("base64");
const response = await fetch("https://api.html2pdf.online/v1/convert", {
method: "POST",
headers: {
Authorization: `Basic ${auth}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
source: "<html><body><h1>Invoice #1024</h1></body></html>",
}),
});
if (!response.ok) {
throw new Error(`Convert failed: ${response.status}`);
}
const pdfBuffer = Buffer.from(await response.arrayBuffer());
await fs.writeFile("invoice.pdf", pdfBuffer);Production checklist
- Store API keys in environment variables, never in source code.
- Use async conversion endpoints for batch jobs and heavy documents.
- Log request IDs and API errors to debug rendering issues quickly.