PDF Generation API

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

Features

  • Generate PDFs from URLs or HTML content

  • Merge multiple PDFs into one (including the one you generated from HTML)

  • 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 and/or urls in the request body (JSON or form data). The HTML content is placed first, followed by the URLs in order. PDF and images URLs are all supported.

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 PDF document withContent-Type: application/pdf.

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