Provides a REST endpoint to create PDF documents from an HTML string using Puppeteer.
Available at DockerHub.
docker run --rm -it \
-p 5000:5000 \
treibholzhq/html2pdf
The API can be secured with an API key using the API_KEY
environment variable.
If you do that, you need to send a bearer token with each request (see Examples)
docker run --rm -it \
-p 5000:5000 \
-e API_KEY=mysecretkey
treibholzhq/html2pdf
The API is exposed on port 5000
inside the container.
Once the container is running, you can send an HTTP POST request with a JSON body of the following structure:
{
"html": "<h1>Hello, World!</h1>",
"options": { }
}
The options
object resembles the Puppeteer PDFOptions
interface.
curl http://localhost:5000/ -o out.pdf \
--json '{"html": "<h1>Hello, World!</h1>"}'
curl http://localhost:5000/ -o out.pdf \
-H 'Authorization: Bearer mysecretkey' \
--json '{"html": "<h1>Hello, World!</h1>"}'
curl http://localhost:5000/ -O -J \
--json '{"html": "<h1>Hello, World!</h1>", "options": { "path": "xyz.pdf" }}'
In this example, the target filename will be taken from the Content-Disposition
response header.
curl http://localhost:5000/ -o out.pdf \
--json '{"html": "<h1>Hello, World!</h1>", "options": { "format": "A4", "landscape": true }}'
This project is licensed under the MIT License - see the LICENSE file for details.