API to generate PDFs from URLs or raw HTML
3.0K
A production‑ready microservice for generating PDFs from URLs or raw HTML, powered by Puppeteer + Chromium.
Includes advanced features such as custom PDF options, presets, language override, one‑page mode, and a cookie‑banner detector.
/health endpoint + Docker HEALTHCHECKInstall dependencies:
npm install
Start the server:
HOST=127.0.0.1 PORT=3000 node server.js
Pull latest image:
docker pull sharevb/puppeteer-htmltopdf:latest
Run it with access to the host Docker daemon:
docker run \
-p 3000:3000 \
-v /var/run/docker.sock:/var/run/docker.sock \
sharevb/puppeteer-htmltopdf:latest
| Variable | Default | Description |
|---|---|---|
HOST | 0.0.0.0 | Interface to bind the HTTP server |
PORT | 3000 | Port to listen on |
CORS | * | CORS Allowed Origins |
/pdf/urlGenerate a PDF from a remote URL.
{
"url": "https://example.com",
"options": {
"format": "A4",
"landscape": false,
"printBackground": true,
"onePage": false,
"language": "en-US",
"autoHideCookies": true,
"margin": {
"top": "20mm",
"bottom": "20mm",
"left": "15mm",
"right": "15mm"
}
}
}
application/pdf binary stream.
/pdf/htmlGenerate a PDF from raw HTML.
{
"html": "<h1>Hello PDF</h1>",
"options": { ... }
}
/healthSimple healthcheck endpoint.
{ "landscape": true }
{ "onePage": true }
Automatically disables format and sets dynamic height.
{ "language": "fr-FR" }
Applies to:
Accept-Language headernavigator.languagenavigator.languages{ "autoHideCookies": true }
Use a preset:
{ "profile": "invoice" }
Available presets:
minimalfullbleedinvoicebookletletterlegalPresets merge deterministically with user overrides.
--no-sandbox for container compatibility; use sandboxing in trusted environments.MIT
Content type
Image
Digest
sha256:e5b3884c5…
Size
618.9 MB
Last updated
2 months ago
docker pull sharevb/puppeteer-htmltopdf