This project provides a CLI and a web-based API service for converting Markdown files into PDF and optionally HTML files.
- Convert Markdown files to PDF with syntax highlighting.
- Optionally generate an HTML version of the output.
- Custom CSS support for styling.
- Adjustable page size and margins.
- List available code highlighting styles.
- FastAPI-based web service with RESTful API.
pip install xpdf
To install the required dependencies, use:
pip install -r requirements.txt
python convert.py [INPUT_FILE] [OUTPUT_FILE] [OPTIONS]
INPUT_FILE
(optional): Path to the Markdown file.OUTPUT_FILE
(optional): Output PDF file path.
--style, -s
(default:xcode
): Code highlighting style.--css, -c
: Path to a custom CSS file.--page-size
(default:A4
): Page size options (e.g.,Letter
,A3
).--margin
(default:0.05in
): Page margin settings.--html, -h
: Also generate an HTML file.--list-styles, -l
: List all available code highlighting styles.
python convert.py sample.md sample.pdf --html --style=monokai
You can run the FastAPI web service to provide Markdown-to-PDF conversion:
python serve.py --host 127.0.0.1 --port 8882
POST /api/topdf
Parameters:
mdcontent
: Markdown content as a form parameter.
Response:
- Returns the generated PDF file.
GET /health
Response:
{"status": "ok"}
To start the web server:
python serve.py
By default, the server runs on http://127.0.0.1:8882/
.
Click
for the CLI interface.FastAPI
andUvicorn
for the web service.MarkdownConverter
for conversion logic.emoji
https://github.com/googlefonts/noto-emoji
This project is licensed under the MIT License.