Inkspan › Next.js

How to generate a PDF from HTML in Next.js

Call the Inkspan /v1/generate/html endpoint from Next.js to generate a PDF from HTML — no headless browser, fonts, or PDF infrastructure to maintain. Set your API key as an environment variable and POST.

Next.js example

// app/api/pdf/route.ts
export async function POST() {
  const res = await fetch('https://api.inkspan.dev/v1/generate/html', {
    method: 'POST',
    headers: { 'X-API-Key': process.env.INKSPAN_KEY!, 'Content-Type': 'application/json' },
    body: JSON.stringify({"html":"<h1>Invoice</h1>"}),
  });
  return new Response(await res.arrayBuffer(), { headers: { 'Content-Type': 'application/pdf' } });
}
Get a free API key →