Doc API
Node.js PDF API

HTML to PDF in Node.js without Puppeteer

One npm install @docapi/sdk. No 150MB Chromium download, no binary dependencies. TypeScript-first, ESM and CJS, works in Next.js, Express, Lambda, and any Node.js 18+ environment.

Free tier: 100 PDFs/month. No credit card required.

30-second quickstart

Install and generate your first PDF

The DocAPI SDK is a zero-dependency TypeScript package that ships both ESM and CJS builds. It works in any Node.js runtime including AWS Lambda, Vercel Functions, and Cloudflare Workers without any additional configuration or binary layers.

  • npm install @docapi/sdk — zero transitive dependencies
  • Full TypeScript types included out of the box
  • ESM and CJS — works with import and require
  • Node.js 18+, Bun, Deno compatible
  • A4 / Letter / custom page dimensions
  • Returns a Buffer — stream or write directly
generate-pdf.ts
import { DocAPI } from "@docapi/sdk";
import fs from "fs";

const client = new DocAPI(process.env.DOCAPI_KEY!);

const pdf = await client.pdf("<h1>Hello World</h1>", { format: "A4" });

fs.writeFileSync("output.pdf", pdf);

Drop into your existing Node.js stack

Works with Next.js App Router, Express, and any other Node.js framework.

Next.js App Router

API route returning a PDF response

// app/api/invoice/[id]/route.ts
import { DocAPI } from "@docapi/sdk";

const client = new DocAPI(process.env.DOCAPI_KEY!);

export async function GET(
  req: Request,
  { params }: { params: { id: string } }
) {
  const invoice = await getInvoice(params.id);
  const html = renderInvoiceHtml(invoice);

  const pdf = await client.pdf(html, { format: "A4" });

  return new Response(pdf, {
    headers: {
      "Content-Type": "application/pdf",
      "Content-Disposition": `inline; filename="invoice-${params.id}.pdf"`,
    },
  });
}

Express route

Serve PDFs from an Express endpoint

import express from "express";
import { DocAPI } from "@docapi/sdk";

const app = express();
const client = new DocAPI(process.env.DOCAPI_KEY!);

app.get("/invoices/:id.pdf", async (req, res) => {
  const html = await buildInvoiceHtml(req.params.id);
  const pdf = await client.pdf(html, { format: "A4" });

  res.setHeader("Content-Type", "application/pdf");
  res.setHeader(
    "Content-Disposition",
    `inline; filename="invoice-${req.params.id}.pdf"`
  );
  res.send(pdf);
});
raw-fetch.ts
const response = await fetch("https://api.docapi.co/v1/pdf", {
  method: "POST",
  headers: {
    "x-api-key": process.env.DOCAPI_KEY!,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    html: "<h1>Hello World</h1>",
    options: { format: "A4", printBackground: true },
  }),
});

const pdf = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("output.pdf", pdf);
No SDK required

Just use fetch — no SDK needed

The API is a plain HTTP endpoint. If you prefer not to add a package, use the global fetch available in Node.js 18+. The SDK is just a typed, ergonomic wrapper around the same call.

  • POST https://api.docapi.co/v1/pdf
  • x-api-key header for authentication
  • JSON body with html and options
  • Response is raw PDF bytes (Buffer)
  • Works with Node.js native fetch — no axios needed

Common Node.js PDF use cases

Invoice PDFs in Next.js

Generate invoice PDFs on demand in a Next.js App Router API route. Render your React invoice component to HTML, send to DocAPI, return the PDF.

Serverless PDF generation

No Chromium layer on Lambda. DocAPI handles the browser — your function stays under 50MB and cold-starts in milliseconds.

Automated report exports

Schedule nightly report PDF generation with a cron job. Query your DB, build an HTML report, generate the PDF, email or upload to S3.

Contract and agreement PDFs

Generate legal documents from HTML templates with per-user data. Stream PDFs directly to the browser or save to cloud storage.

SaaS document exports

Let users export any page or data view as a PDF. One API call replaces a full Puppeteer setup with browser management.

E-commerce receipts

Generate branded purchase receipts and order confirmations as PDFs, attached to transactional emails or available for download.

vs. Puppeteer, html-pdf, and puppeteer-core

Other Node.js PDF solutions require shipping a 150MB+ Chromium binary or wkhtmltopdf to your server.

FeatureDocAPIPuppeteerhtml-pdfpuppeteer-core
No binary download150MB ChromiumwkhtmltopdfBring your own
Works in LambdaComplex layerComplex layer
Cold start~10ms3–5s~500ms3–5s
TypeScript typesPartial
Full CSS supportPartial
Zero npm deps
Free tier100/moSelf-hostedSelf-hostedSelf-hosted

Start generating PDFs in Node.js today

Free tier includes 100 PDFs per month — no credit card, no Chromium, no infrastructure to manage.

HTML to PDF Node.js API — Generate PDFs from Node.js & TypeScript | Doc API