---
name: php186-skill-18427
description: "将 Markdown文件转换为美观的 PDF，支持自定义样式、代码高亮和多种输出选项，适用于需要将 Markdown 转换为 PDF 的场景。"
---

# Markdown to PDF

## markdown-to-pdf

 

## Overview

 

Convert Markdown text or files to professional-looking PDF documents. Uses ` markdown ` package to convert MD to HTML, then ` wkhtmltopdf ` to generate PDF. Supports code syntax highlighting and custom CSS styling.

 

## Features

 

- **Convert MD file to PDF**: Take a Markdown file and output a ready-to-share PDF
- **Standalone output**: Embeds all styles, no external dependencies
- **Code highlighting**: Automatic syntax highlighting for code blocks
- **Custom CSS**: Option to provide custom CSS for styling

 

## Dependencies

 

```
pip install markdown pygments
# You also need wkhtmltopdf installed:
# macOS: brew install wkhtmltopdf
# Ubuntu/Debian: sudo apt install wkhtmltopdf
```

 

## Usage

 

### Basic conversion

 

```
python3 scripts/convert.py input.md output.pdf
```

 

### With custom CSS

 

```
python3 scripts/convert.py --css custom.css input.md output.pdf
```

 

## Resources

 

### scripts/

 

- ` convert.py ` - Convert Markdown file to PDF
