Sign inSign up

quphoria/html-to-pdf

By quphoria

•Updated about 1 year ago

Image
0

447

quphoria/html-to-pdf repository overview

⁠HTML to PDF Service

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⁠

⁠Features

  • 🚀 Fast and async PDF generation using Playwright
  • 🎯 Accurate HTML rendering using a real browser
  • 🔒 Optional API key authentication
  • 🌐 Proxy support
  • 🖼️ Media blocking capabilities
  • 🐳 Docker support
  • 🏗️ CI/CD with GitHub Actions
  • 📚 Interactive API documentation (Swagger UI)

⁠Quick Start

⁠Using Docker Compose
  1. Clone the repository:
git clone [email protected]:Quphoria/html_to_pdf.git
cd html_to_pdf
  1. Set up environment variables:
cp .env.example .env
  1. Edit .env file with your settings:
AUTH_API_KEY=your-secret-api-key
PORT=8000
HOST=0.0.0.0
  1. Build and run with Docker Compose:
docker compose up --build

The service will be available at http://localhost:8000

Access the interactive API documentation at http://localhost:8000/docs

⁠Using Docker Hub Image
docker pull quphoria/html-to-pdf:latest
docker run -p 8000:8000 -e AUTH_API_KEY=your-secret-key quphoria/html-to-pdf

⁠API Documentation

The API documentation is available through Swagger UI at /docs endpoint. This provides:

  • Interactive API documentation
  • Request/response examples
  • Try-it-out functionality
  • OpenAPI specification
⁠Available Endpoints
⁠Health Checks
  • GET /health/liveness - Liveness probe
  • GET /health/readiness - Readiness probe
⁠PDF Generation Fetching
  • POST /pdf - Fetch HTML content from a URL and return a generated PDF
⁠Request Body
{
  "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"
  }
}

⁠Authentication

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"}'

⁠Development

⁠Local Setup
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Install Playwright browsers:
playwright install chromium-headless-shell
  1. Run the application:
uvicorn main:app --reload
  1. Access the API documentation:
    • Open http://localhost:8000/docs in your browser
    • Try out the endpoints directly from the Swagger UI
    • View the OpenAPI specification at /openapi.json

⁠Environment Variables

VariableDescriptionDefault
AUTH_API_KEYAPI key for authenticationNone (disabled)
PORTServer port8000
HOSTServer host0.0.0.0
PYTHONUNBUFFEREDPython unbuffered output1

⁠Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

⁠License

This project is licensed under the MIT License - see the LICENSE file for details.

Tag summary

Content type

Image

Digest

sha256:c0299a6c1…

Size

929.2 MB

Last updated

about 1 year ago

docker pull quphoria/html-to-pdf