A powerful and easy-to-use API service that converts Markdown text into high-quality PDF documents. Built with FastAPI and Playwright, and ready to be deployed as a Docker container.
- High-Quality Rendering: Uses a real browser engine (Chromium) for accurate rendering.
- LaTeX Math Support: Beautifully renders LaTeX math formulas using KaTeX.
- GitHub Flavored Markdown: Supports tables, strikethrough, and other GFM features.
- API-First Design: Easy to integrate with other services and workflows.
- Containerized: Simple to deploy and run anywhere with Docker.
This service is designed to be run as a Docker container.
First, build the Docker image from the Dockerfile. Open your terminal in the project's root directory and run:
docker build -t md2pdf-service .Once the image is built, you can start the service with the following command:
docker run --rm -p 8020:8020 md2pdf-serviceThis will start the API server, and you can access it at http://localhost:8020.
The API provides a single endpoint to convert Markdown to PDF.
The easiest way to use the API is through the interactive documentation (Swagger UI), which is automatically generated by FastAPI.
- Open your browser and navigate to: http://localhost:8020/docs
From there, you can directly paste your Markdown text and get the PDF file back.
You can also use any HTTP client, like curl, to send a request.
curl -X POST "http://localhost:8020/convert" \
-H "Content-Type: text/markdown" \
--data-binary "@path/to/your/file.md" \
-o output.pdf- Replace
@path/to/your/file.mdwith the path to your local Markdown file. - The generated PDF will be saved as
output.pdf.
If you want to run the service locally without Docker:
- Install dependencies using
uv:# This will create a virtual environment and install all dependencies uv pip sync pyproject.toml - Install Playwright browser dependencies:
uv run playwright install chromium
- Run the development server:
# --reload will automatically restart the server when you change the code uv run uvicorn server:app --reload