https://github.com/arienshibani/trykkeri-api
π¨οΈ API for turning HTML to PDF
https://github.com/arienshibani/trykkeri-api
docker-image grafana html-to-pdf
Last synced: 4 months ago
JSON representation
π¨οΈ API for turning HTML to PDF
- Host: GitHub
- URL: https://github.com/arienshibani/trykkeri-api
- Owner: arienshibani
- Created: 2026-02-13T15:32:09.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-02-13T16:30:15.000Z (4 months ago)
- Last Synced: 2026-02-14T00:10:26.759Z (4 months ago)
- Topics: docker-image, grafana, html-to-pdf
- Language: Go
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Trykkeri API π¨οΈ
[](https://go.dev/)
[](https://swagger.io/specification/)
[](https://www.docker.com/)
[](https://grafana.com/)
REST API for turning raw HTML into PDF files, with built-in monitoring.
## Features β¨
- **HTML to PDF** - Either supply raw HTML to `/print`, or use the `/mirror` endpoint to fetch the HTML directly from a webpage.
- **Grafana dashboard** - Preconfigured with a custom dashboard for monitoring usage and errors (when run with the observability stack).
- **Scalar UI** - Interactive API docs for trying different HTML and query parameters.
- **Tunable output** - Margins, page size, filename, DPI, orientation, background printing, grayscale etc. All using query parameters.
## Usage π
Send a `POST` request to `/print` with your HTML as the request body.
```bash
curl http://localhost:8080/print \
--request POST \
--header 'Content-Type: text/html' \
--header 'Accept: application/pdf' \
--data '
Hello world!
'
```
### Output π

## Endpoints π
- **`/print`** β `POST` request with HTML in the body β **PDF**.
- **`/mirror`** β `POST` request with a URL in the body β we fetch the HTML β **PDF**
### Optional query parameters π§
| Parameter | Type | Description |
| ----------- | ------ | ------------- |
| `filename` | string | Suggested filename in `Content-Disposition` (default: `document.pdf`) |
| `base_url` | string | Base URL for resolving relative links and assets in the HTML |
| `page_size` | string | e.g. `A4`, `Letter` |
| `portrait` | boolean | `true` = portrait, `false` = landscape |
| `margin_top_mm` | integer | Top margin in mm |
| `margin_right_mm` | integer | Right margin in mm |
| `margin_bottom_mm` | integer | Bottom margin in mm |
| `margin_left_mm` | integer | Left margin in mm |
| `dpi` | integer | Output DPI (e.g. `300`) |
| `print_background` | boolean | Include CSS background graphics |
| `grayscale` | boolean | Render in grayscale |
Example with options:
```bash
curl 'http://localhost:8080/print?filename=report.pdf&page_size=A4&margin_top_mm=20&dpi=150' \
--request POST \
--header 'Content-Type: text/html' \
--data '
Report
'
```
## Quickstart π
Ensure you have the following installed
- [Docker](https://www.docker.com/)
- [Go](https://go.dev/)
- [Justfile](https://github.com/casey/just) (optional, but recommended)
### 1. Clone the repository
```bash
git clone https://github.com/trykkeri/trykkeri-api.git
cd trykkeri-api
```
### 2. Spin up the services
**API only** (Go, no Docker):
```bash
just run
# or: go run ./cmd/server
```
**Full stack** (API + Grafana, Loki, Promtail in Docker, with live reload):
```bash
just watch
# or: docker compose --profile observability watch
```
### 3. Access the services
- π **API / Scalar UI** β (available with either `just run` or `just watch`).
- πͺ΅ **Grafana dashboard** β (only when you use `just watch`).
## Configuration π§
The service can be configured using environment variables. When you run the stack with Docker Compose, set these in a `.env` file in the project rootβthe same file used for Grafana (e.g. `GRAFANA_ADMIN_USER`). See [.env.example](.env.example) for a template.
| Variable | Description | Default |
| ---------- | ------------- | ------- |
| `PORT` | The port the service listens on | `8080` |
| `JSON_LOGS` | Whether to log in JSON format | `false` |
| `MAX_BODY_BYTES` | The maximum body size in bytes | `2000000` |
| `RENDER_TIMEOUT_MS` | The timeout in milliseconds for rendering a PDF | `30000` |
| `WKHTMLTOPDF_PATH` | The path to the wkhtmltopdf binary | `wkhtmltopdf` |
| `ALLOW_NET` | Whether to allow network access | `false` |
## Screenshots πΈ
### API

### Grafana

### Pre-built image
New image on every commit to main can be fetched from Github Container Registry.
```bash
docker run -p 8080:8080 ghcr.io/trykkeri/trykkeri-api:latest
```
Images are published on every push to `main` and when you create a release. Use `:latest`, `:sha-`, or a version tag (e.g. `:v1.0.0`) after a release.