Skip to content

A Restful API for print PDF with WeasyPrint.

License

Notifications You must be signed in to change notification settings

timfanda35/weasyprint-pdf-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeasyPrint PDF API

A Restful API for print PDF with WeasyPrint.

Use the pre-build container image

Pull Image

docker pull ghcr.io/timfanda35/weasyprint-pdf-api:latest

Or use specific version

docker pull ghcr.io/timfanda35/weasyprint-pdf-api:1.0.0

Run Container

Run with default port 8000

docker run -it --rm -p 8000:8000 ghcr.io/timfanda35/weasyprint-pdf-api:latest

Run with specific port, like 8080

docker run -it --rm -p 8080:8080 -e PORT=8080 ghcr.io/timfanda35/weasyprint-pdf-api:latest

Access Swagger UI

Open http://localhost:8000/docs in the browser.

Send Request

POST /pdfs, for example:

{ "html": "<h1>Hello World</h1>" }

Response will be streaming download.

You can also specific filename:

{ "filename": "shipping-label", "html": "<h1>Hello World</h1>" }

Development

1. Build container image

make build

2. Attach container

It create a container and bind port 8000.

make dev-console

3. Start server

uvicorn main:app --reload --host 0.0.0.0

Test

Install httpx and pytest

pip install httpx pytest

Run test cases

pytest