Skip to content

masterlyj/md2pdf_service

Repository files navigation

Markdown to PDF Converter API

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.

Features

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

Requirements

How to Run

This service is designed to be run as a Docker container.

1. Build the Docker Image

First, build the Docker image from the Dockerfile. Open your terminal in the project's root directory and run:

docker build -t md2pdf-service .

2. Run the Docker Container

Once the image is built, you can start the service with the following command:

docker run --rm -p 8020:8020 md2pdf-service

This will start the API server, and you can access it at http://localhost:8020.

How to Use the API

The API provides a single endpoint to convert Markdown to PDF.

Interactive API Docs (Recommended)

The easiest way to use the API is through the interactive documentation (Swagger UI), which is automatically generated by FastAPI.

From there, you can directly paste your Markdown text and get the PDF file back.

Using curl

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.md with the path to your local Markdown file.
  • The generated PDF will be saved as output.pdf.

For Local Development (Optional)

If you want to run the service locally without Docker:

  1. Install dependencies using uv:
    # This will create a virtual environment and install all dependencies
    uv pip sync pyproject.toml
  2. Install Playwright browser dependencies:
    uv run playwright install chromium
  3. Run the development server:
    # --reload will automatically restart the server when you change the code
    uv run uvicorn server:app --reload

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors