PDF Generation API

A powerful, easy-to-use API for generating PDF documents from HTML content or URLs.

Features

  • Generate PDFs from URLs, raw HTML content, uploaded files, or data URLs

  • Merge multiple PDFs/pages/images into a single PDF document

  • Powered by Puppeteer and headless Chromium

  • Serverless deployment ready

  • Open source

  • Customizable page settings (soon, open to contribution)

Get started

This hosted API is provided for demonstration purposes only. Please fork the repository and deploy your own instance.

This API is not versioned and breaking changes may occur, even if best effort is made to avoid them. Owning your deployment means you stay in control of updates and stability.

You can fork the repository on GitHub anddeploy it to Vercel.

To generate a PDF, make a POST request to /api/gen with html, urls (page, PDF, or image URLs, or data URLs), and/or files (direct file uploads, 4 MB max) in the request body (JSON or form data). For JSON bodies, items are always merged in the fixed order urlsfileshtml, regardless of the order you write them in — for multipart form data, items are merged in the order the fields were submitted.

curl -X POST 'https://pdf.mathieutu.dev/api/gen' \
  --header 'Content-Type: application/json' \
  --output 'foo.pdf' \
  --data-raw '{
    "filename": "foo.pdf",
    "html": "<html><head><script src=\"https://cdn.tailwindcss.com\"></script></head><body class=\"h-screen grid place-items-center\"><span class=\"print:hidden\">IT SHOULD NOT BE PRINTED</span><div class=\"bg-pink-300 text-pink-800 p-8 h-25 grid place-items-center font-medium font-mono\">@mathieutu</div></body></html>",
    "urls": [
      "https://pdf.mathieutu.dev",
      "https://www.troglos.fr/og-image.jpg",
      "https://pour-un-reveil-ecologique.org/documents/54/10_key_points_IPCC_1_2_and_3.pdf"
    ]
  }'

You can also directly pass URLs as query parameters in a GET request: https://pdf.mathieutu.dev/api/gen?url=https://pdf.mathieutu.dev&url=https://www.troglos.fr/og-image.jpg&url=https://pour-un-reveil-ecologique.org/documents/54/10_key_points_IPCC_1_2_and_3.pdf

The response is always a single merged PDF document with Content-Type: application/pdf, whatever the mix or number of inputs.

A Docker image is published on GitHub Container Registry on every release. Pin the major tag (e.g. 1) to get fixes and new features automatically while staying protected from breaking changes:

docker run -p 3000:3000 ghcr.io/mathieutu/pdf-gen:1

Framework Integrations

Laravel — example service to generate and merge PDFs from a Laravel app.

TypeScript — fluent client (Node & browser) built on the Fetch API.

Playground

Try the API directly from your browser.

Method

Urls & Files(optional)

Mathieu TUDISCO

Trainer and pragmatic full-stack lead developer, currently open to short freelance assignments (let's talk!). Passionate about PHP and TypeScript, regular open-source contributor.

When I'm not in front of a screen, you'll usually find me cycling around Lyon, or in the surrounding mountains, where I spend a fair amount of time underground and under waterfalls...

pdf-gen is an open-source side project, born from the need for a simple, self-hostable API to generate and merge PDFs without vendor lock-in or per-document pricing.

View contributors