An open API service indexing awesome lists of open source software.

https://github.com/mathieutu/pdf-gen

Generate a pdf from html content.
https://github.com/mathieutu/pdf-gen

Last synced: about 1 year ago
JSON representation

Generate a pdf from html content.

Awesome Lists containing this project

README

          

# PDF Generator

A simple API to generate PDFs from URLs or HTML content, powered by Puppeteer and headless Chromium. This project is open-source and serverless deployment ready.

## 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 (coming soon, open to contributions)

## Get Started

You can try it out on https://pdf.mathieutu.dev.
This URL is provided for demonstration purposes only.

Please deploy it on your own infrastructure, or I'll have to shut it down.
You can do it freely on Vercel [with one click](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fmathieutu%2Fpdf-gen).

To generate a PDF, you can make a JSON POST request to the `/api/gen` endpoint with either a `url` or `html` parameter in the request body.
You can also merge multiple PDFs by passing an array of PDF URLs in the `merge` parameter. The merged PDF will be returned as a single document.

```bash
curl -X POST 'https://your-deployment-url/api/gen' \
--header 'Content-Type: application/json' \
--output 'foo.pdf' \
--data-raw '{
"filename": "foo.pdf",
"html": "<\/script><\/head><body class=\"h-screen grid place-items-center\"><span class=\"print:hidden\">IT SHOULD NO BE PRINTED<\/span><div class=\"bg-pink-300 text-pink-800 p-8 h-[100px] grid place-items-center font-medium font-mono\">@mathieutu<\/div><\/body><\/html>"
"merge": [
"https://pour-un-reveil-ecologique.org/documents/54/10_key_points_IPCC_1_2_and_3.pdf",
]
}'
```

Alternatively, you can directly pass a URL as a query parameter in a GET request:

```bash
https://your-deployment-url/api/gen?url=https://example.com&merge=https://example.com/another.pdf&merge=https://example.com/yet-another.pdf
```

The response will be a PDF document with the appropriate content type headers.

## The Author

This project was created by [@mathieutu](https://mathieutu.dev), a passionate developer focused on building open-source tools and APIs.

Feel free to contribute to the project or [reach out](mailto:contact@mathieutu.dev) for collaboration opportunities.