Rest API service that converts HTML and CSS into high‑quality PDFs.
The service can create PDF files by rendering an HTML-file using CSS. Additionally, attachments can be supplied that will be rendered to the end of the created PDF-file. Files reverenced in the HTML (like images) also need to be sent to the service so they can be used during the rendering.
The request is sent to the /pdf endpoint and returns the created PDF-file. The rendering might take a while (especially for PDF files with many pages).
Example:
curl -X POST "$HOST/pdf" -F "html=@./sbgg.html" -F "css=@./norm.css" -F "attachments=@./sbgg-attachment-1.pdf" -F "attachments=@./sbgg-attachment-2.pdf" -F "files=@./sbgg-image-1.png" -F "files=@./sbgg-image-2.png" -o sbgg.pdfTo build and run the application, you'll need:
- Docker, for infrastructure or running a containerized version of the entire application locally
- A Python 3 Installation
If you would like to make changes to the application, you'll also need:
talisman, for preventing accidentially committing sensitive datalefthook, for running Git hooksgh, for checking the pipeline status before pushingdocker, for running containers-pythonas runtimepango stackdependency of weasyprintuvPython package and project manager
If you use Homebrew, you can install all of them like this:
brew install talisman lefthook gh
brew install python
brew install pango cairo harfbuzz fontconfig freetype pkg-config
brew install --cask docker # or `brew install docker` if you don't want the desktop appInstall uv by running:
curl -LsSf https://astral.sh/uv/install.sh | shor
brew install uvOnce you installed the prerequisites, make sure to initialize Git hooks. This will ensure any code you commit follows our coding standards, is properly formatted, and has a commit message adhering to our conventions:
lefthook installDownload dependencies:
uv syncStart dev server:
uv run python -m fastapi dev src/main.py --host 0.0.0.0 --port 8080Test manually:
curl -X POST http://localhost:8080/pdf -F "html=@./sbgg.html" -F "css=@./style.css" -o sbgg.pdfRun tests:
uv run pytestRun linter
uv run flake8 ./srcRun formatter
uv run black ./srcIf you would like to contribute, check out CONTRIBUTING.md. Please also consider our Code of Conduct.
- 🔒 OpenAPI docs or while the application is running locally under http://localhost:8080/docs
- How to use weasyprint with tailwind
- Accessibility
- PDF/A Conformance