Metadata-Version: 2.4
Name: markdown-pdf-converter
Version: 1.0.0
Summary: A Python library to convert Markdown files to PDF with Chinese support
Author-email: louischerry <louischerry@126.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/markdown-pdf-converter
Project-URL: Documentation, https://github.com/yourusername/markdown-pdf-converter#readme
Project-URL: Repository, https://github.com/yourusername/markdown-pdf-converter
Project-URL: Issues, https://github.com/yourusername/markdown-pdf-converter/issues
Keywords: markdown,pdf,converter,chinese,reportlab
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup
Classifier: Topic :: Utilities
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: reportlab>=3.6.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: flake8>=5.0.0; extra == "dev"
Dynamic: license-file

# Markdown PDF Converter

[![PyPI version](https://badge.fury.io/py/markdown-pdf-converter.svg)](https://badge.fury.io/py/markdown-pdf-converter)
[![Python version](https://img.shields.io/pypi/pyversions/markdown-pdf-converter.svg)](https://pypi.org/project/markdown-pdf-converter/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

A Python library to convert Markdown files to PDF with **Chinese support** and **intelligent code wrapping**.

## ✨ Features

- 📝 **Markdown to PDF**: Convert Markdown files to beautifully formatted PDF documents
- 🇨🇳 **Chinese Support**: Automatic Chinese font detection and rendering
- 💻 **Code Block Handling**: Smart formatting for code blocks with proper line wrapping
- 🎨 **Customizable Styles**: Multiple style presets (default, compact, large print)
- 🔧 **Flexible Configuration**: Customize fonts, margins, font sizes, and colors
- 🚀 **Command Line Interface**: Easy-to-use CLI for quick conversions
- 📦 **Pure Python**: No external dependencies except reportlab

## 📦 Installation

```bash
pip install markdown-pdf-converter
```

### Development Installation

```bash
git clone https://github.com/yourusername/markdown-pdf-converter.git
cd markdown-pdf-converter
pip install -e ".[dev]"
```

## 🚀 Quick Start

### Command Line Usage

```bash
# Basic conversion
md2pdf input.md

# Specify output file
md2pdf input.md -o output.pdf

# Use compact style for dense content
md2pdf input.md --style compact

# Use custom font
md2pdf input.md --font /path/to/chinese/font.ttf

# Customize font sizes and margins
md2pdf input.md --title-size 18 --body-size 10 --margin 2.5
```

### Python API Usage

```python
from markdown_pdf_converter import MarkdownToPDFConverter
from markdown_pdf_converter.styles import PDFStyles

# Basic usage
converter = MarkdownToPDFConverter()
converter.convert("input.md", "output.pdf")

# With custom font
converter = MarkdownToPDFConverter(font_path="/path/to/font.ttf")
converter.convert("input.md", "output.pdf")

# With custom styles
styles = PDFStyles(
    title_font_size=20,
    body_font_size=11,
    right_margin=2.5,
    left_margin=2.5
)
converter = MarkdownToPDFConverter()
converter.convert("input.md", "output.pdf", **styles.to_dict())

# Use preset styles
converter = MarkdownToPDFConverter()
converter.convert("input.md", "output.pdf", **PDFStyles.compact().to_dict())
```

## 📖 Supported Markdown Features

- ✅ Headers (H1, H2, H3)
- ✅ Bold and italic text
- ✅ Lists (ordered and unordered)
- ✅ Code blocks and inline code
- ✅ Blockquotes
- ✅ Links
- ✅ Horizontal rules
- ✅ Tables (simplified)

## 🎨 Style Presets

### Default Style
Standard formatting suitable for most documents.

```python
from markdown_pdf_converter.styles import PDFStyles
styles = PDFStyles.default()
```

### Compact Style
Optimized for dense content like technical documentation.

```python
from markdown_pdf_converter.styles import PDFStyles
styles = PDFStyles.compact()
```

### Large Print Style
Enhanced readability with larger fonts.

```python
from markdown_pdf_converter.styles import PDFStyles
styles = PDFStyles.large_print()
```

## 🔧 Configuration Options

### PDFStyles Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `page_size` | str | "A4" | Page size (A4, Letter, Legal) |
| `right_margin` | float | 2.0 | Right margin in cm |
| `left_margin` | float | 2.0 | Left margin in cm |
| `top_margin` | float | 2.0 | Top margin in cm |
| `bottom_margin` | float | 2.0 | Bottom margin in cm |
| `title_font_size` | int | 16 | H1 font size |
| `heading_font_size` | int | 13 | H2 font size |
| `subheading_font_size` | int | 11 | H3 font size |
| `body_font_size` | int | 9 | Body text font size |
| `code_font_size` | int | 8 | Code block font size |

## 🌐 Chinese Font Support

The library automatically detects and uses Chinese fonts from common system locations:

- **macOS**: PingFang, STHeiti, Hiragino Sans GB
- **Linux**: WQY Zenhei, WQY Microhei, Noto Sans CJK
- **Windows**: SimSun, Microsoft YaHei (add your font path manually)

### Custom Font

If automatic detection fails, specify a font path:

```python
converter = MarkdownToPDFConverter(font_path="/path/to/your/font.ttf")
```

## 🧪 Testing

```bash
# Run tests
pytest

# Run tests with coverage
pytest --cov=markdown_pdf_converter

# Run linting
black markdown_pdf_converter/
flake8 markdown_pdf_converter/
```

## 📁 Project Structure

```
markdown-pdf-converter/
├── markdown_pdf_converter/     # Main package
│   ├── __init__.py
│   ├── converter.py           # Core conversion logic
│   ├── styles.py              # Style configuration
│   └── cli.py                 # Command line interface
├── tests/                      # Test files
├── examples/                   # Example files
├── pyproject.toml             # Package configuration
├── README.md                  # This file
└── LICENSE                    # MIT License
```

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## 📝 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🐛 Issues

If you encounter any issues or have suggestions, please [open an issue](https://github.com/yourusername/markdown-pdf-converter/issues).

## 🙏 Acknowledgments

- Built with [ReportLab](https://www.reportlab.com/) - PDF generation library
- Inspired by the need for simple Markdown to PDF conversion with Chinese support

---

**Happy Converting!** 🎉
