How to generate a PDF with Node.js

Generate PDFs from Node.js using an async first SDK that fits Express, Next.js, and serverless functions. Convert HTML or URLs into PDFs that render with modern CSS.

import { GeneratePDFs } from '@generatepdfs/node-sdk';

const client = GeneratePDFs.connect('YOUR_API_TOKEN');

// Generate from HTML file with CSS
const pdf = await client.generateFromHtml(
    '/path/to/file.html',
    '/path/to/file.css'
);

// Or from a URL
const pdf = await client.generateFromUrl('https://example.com');
from generatepdfs import GeneratePDFs

client = GeneratePDFs.connect('YOUR_API_TOKEN')

# Generate from HTML file with CSS
pdf = client.generate_from_html(
    '/path/to/file.html',
    '/path/to/file.css'
)

# Or from a URL
pdf = client.generate_from_url('https://example.com')
<?php
use GeneratePDFs\GeneratePDFs;

$client = GeneratePDFs::connect('YOUR_API_TOKEN');

// Generate from HTML file with CSS
$pdf = $client->generateFromHtml(
    '/path/to/file.html',
    '/path/to/file.css'
);

// Or from a URL
$pdf = $client->generateFromUrl('https://example.com');
<?php
use GeneratePDFs\Laravel\Facades\GeneratePDFs;

// Generate from HTML file with CSS
$pdf = GeneratePDFs::generateFromHtml(
    '/path/to/file.html',
    '/path/to/file.css'
);

// Or from a URL
$pdf = GeneratePDFs::generateFromUrl('https://example.com');
require 'generatepdfs'

client = GeneratePDFs::GeneratePDFs.connect('YOUR_API_TOKEN')

# Generate from HTML file with CSS
pdf = client.generate_from_html(
    '/path/to/file.html',
    '/path/to/file.css'
)

# Or from a URL
pdf = client.generate_from_url('https://example.com')

Generate PDFs in Node.js with async workflows

Convert HTML and CSS to PDF

Render HTML from React, Handlebars, or static templates, then await the SDK call. The browser based renderer keeps modern CSS features aligned with your front end. For HTML to PDF conversion, see the main guide.

Generate PDFs from URLs in Node.js

Send a URL to convert pages into PDFs for reports, invoices, or account pages. This works well for Vercel, Netlify, and AWS Lambda deployments.

Background jobs and workers

Generate PDFs in workers using BullMQ, RabbitMQ, or queue services, then store the result in S3 or object storage. If you use Puppeteer or Playwright for PDFs, see the Alternative to Puppeteer PDF and Alternative to Playwright PDF pages. Use server side PDF generation without browser infrastructure. Use the PDF generation API with the Node SDK.

Install the Node.js SDK with npm

  1. Install the GeneratePDFs Node.js SDK with npm, pnpm, or yarn.
  2. Store your API token in environment variables for your runtime.
  3. Create a small client wrapper so your routes share one connection.
  4. await generateFromHtml or generateFromUrl inside an async handler.
  5. Stream the PDF to the response or upload it to your storage service.

Why Node.js teams choose GeneratePDFs

โš™๏ธ

Async first SDK

Promise based calls fit async routes and serverless handlers.

๐ŸŒ

No headless browser setup

Skip Chromium installs and keep deploys smaller.

๐Ÿ“ฆ

Browser accurate output

Modern HTML and CSS render the same in the PDF.

Common Node.js PDF workflows

๐Ÿงพ

Serverless receipts

Generate PDFs in Next.js or Lambda without local binaries.

๐Ÿ“Š

Reports from React

Convert HTML dashboards and charts into PDFs.

๐Ÿ“„

Multi tenant portals

Create account statements and onboarding PDFs on demand.

Generate PDFs in Node.js with async friendly tooling

Use the Node.js SDK to convert HTML or URLs into PDFs that keep your fonts, colours, and layout.