A FastAPI-based web service that uses Playwright to fetch web content and convert it into a PDF. This service provides a robust API for PDF generation with support for proxies, media blocking, PDF generation options, and API key authentication.
This is a fork of watercrawl/playwright
git clone [email protected]:Quphoria/html_to_pdf.git
cd html_to_pdf
cp .env.example .env
.env file with your settings:AUTH_API_KEY=your-secret-api-key
PORT=8000
HOST=0.0.0.0
docker compose up --build
The service will be available at http://localhost:8000
Access the interactive API documentation at http://localhost:8000/docs
docker pull quphoria/html-to-pdf:latest
docker run -p 8000:8000 -e AUTH_API_KEY=your-secret-key quphoria/html-to-pdf
The API documentation is available through Swagger UI at /docs endpoint. This provides:
/health/liveness - Liveness probe/health/readiness - Readiness probe/pdf - Fetch HTML content from a URL and return a generated PDF{
"url": "https://example.com",
"proxy": {
"type": "http",
"host": "proxy.example.com",
"port": 8080,
"username": "user",
"password": "pass"
},
"block_media": true,
"user_agent": "custom-user-agent",
"locale": "en-US",
"extra_headers": {
"Custom-Header": "value"
},
"pdf_options": {
"print_background": true,
"width": "80mm",
"height": "297mm"
}
}
When AUTH_API_KEY is set in the environment, the API requires authentication using the X-API-Key header:
curl -X POST http://localhost:8000/pdf \
-H "Content-Type: application/json" \
-H "X-API-Key: your-secret-api-key" \
-d '{"url": "https://example.com"}'
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
playwright install chromium-headless-shell
uvicorn main:app --reload
http://localhost:8000/docs in your browser/openapi.json| Variable | Description | Default |
|---|---|---|
| AUTH_API_KEY | API key for authentication | None (disabled) |
| PORT | Server port | 8000 |
| HOST | Server host | 0.0.0.0 |
| PYTHONUNBUFFERED | Python unbuffered output | 1 |
This project is licensed under the MIT License - see the LICENSE file for details.
Content type
Image
Digest
sha256:c0299a6c1…
Size
929.2 MB
Last updated
about 1 year ago
docker pull quphoria/html-to-pdf