A FastAPI-based service that converts URLs, HTML and Word content to PDF documents.
- Convert HTML content to PDF
- Convert URLs to PDF
- Convert Word documents to PDF
- A4 format with customizable margins
- Background graphics and colors support
- Asynchronous processing
- Base64 encoded output
- Clone the repository:
git clone https://github.com/bselleslagh/PyPaperFlow.git
cd PyPaperFlow- Install dependencies using UV:
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .- Install Playwright browsers:
playwright install- Set up pre-commit hooks:
# Install the pre-commit hooks
uv run pre-commit install
# Run pre-commit on all files (optional)
uv run pre-commit run --all-filesdocker build -t pypaperflow .
docker run -p 8000:8000 pypaperflowThe service exposes three endpoints:
GET /Returns a welcome message confirming the service is running.
POST /convert-htmlRequest body:
{
"content": "string",
"type": "html" | "url"
}content: HTML string or URL to converttype: Either "html" for HTML content or "url" for web pages (default: "html")
Response:
{
"pdf": "base64_encoded_string",
"message": "PDF generated successfully"
}POST /convert-wordRequest body:
{
"content": "string" // base64 encoded Word document
}Response:
{
"pdf": "base64_encoded_string",
"message": "Word document converted to PDF successfully"
}import requests
import base64
# Convert HTML to PDF
url = "http://localhost:8000/convert-html"
payload = {
"content": "<h1>Hello World</h1>",
"type": "html"
}
response = requests.post(url, json=payload)
pdf_data = response.json()["pdf"]
# Convert Word to PDF
with open("document.docx", "rb") as word_file:
word_base64 = base64.b64encode(word_file.read()).decode("utf-8")
payload = {
"content": word_base64
}
response = requests.post("http://localhost:8000/convert-word", json=payload)
pdf_data = response.json()["pdf"]- Python ≥ 3.13
- FastAPI
- Playwright
- See
pyproject.tomlfor full dependencies
This project is licensed under the MIT License - see the LICENSE file for details.
Ben Selleslagh (@BenSelleslagh)
Contributions are welcome! Please feel free to submit a Pull Request.