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 and deploy 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 with Content-Type: application/pdf.

Playground

Try the API directly from your browser.

Method

URLs(optional)

The Author

This project was created by @mathieutu, a passionate developer focused on building open-source tools and APIs.

Feel free to contribute to the project or reach out for collaboration opportunities.