Skip to content

Latest commit

 

History

History
98 lines (74 loc) · 3.1 KB

File metadata and controls

98 lines (74 loc) · 3.1 KB

Pdf print service

Rest API service that converts HTML and CSS into high‑quality PDFs.

Usage

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.pdf

Prerequisites

To 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 data
  • lefthook, for running Git hooks
  • gh, for checking the pipeline status before pushing
  • docker, for running containers-
  • python as runtime
  • pango stack dependency of weasyprint
  • uv Python 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 app

Install uv by running:

curl -LsSf https://astral.sh/uv/install.sh | sh

or

brew install uv

Once 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 install

Developing

Download dependencies:

uv sync

Start dev server:

uv run python -m fastapi dev src/main.py --host 0.0.0.0 --port 8080

Test manually:

curl -X POST http://localhost:8080/pdf  -F "html=@./sbgg.html" -F "css=@./style.css" -o sbgg.pdf

Run tests:

uv run pytest

Run linter

uv run flake8 ./src

Run formatter

uv run black ./src

Contributing

If you would like to contribute, check out CONTRIBUTING.md. Please also consider our Code of Conduct.

Documentation