markdown-pdf-converter 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdown_pdf_converter-1.0.0/LICENSE +21 -0
- markdown_pdf_converter-1.0.0/MANIFEST.in +5 -0
- markdown_pdf_converter-1.0.0/PKG-INFO +241 -0
- markdown_pdf_converter-1.0.0/README.md +206 -0
- markdown_pdf_converter-1.0.0/examples/convert_example.py +84 -0
- markdown_pdf_converter-1.0.0/examples/example.md +77 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter/__init__.py +14 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter/cli.py +113 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter/converter.py +315 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter/styles.py +91 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/PKG-INFO +241 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/SOURCES.txt +18 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/dependency_links.txt +1 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/entry_points.txt +2 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/requires.txt +7 -0
- markdown_pdf_converter-1.0.0/markdown_pdf_converter.egg-info/top_level.txt +1 -0
- markdown_pdf_converter-1.0.0/pyproject.toml +64 -0
- markdown_pdf_converter-1.0.0/setup.cfg +4 -0
- markdown_pdf_converter-1.0.0/tests/__init__.py +1 -0
- markdown_pdf_converter-1.0.0/tests/test_converter.py +151 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 markdown-pdf-converter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: markdown-pdf-converter
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python library to convert Markdown files to PDF with Chinese support
|
|
5
|
+
Author-email: louischerry <louischerry@126.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/yourusername/markdown-pdf-converter
|
|
8
|
+
Project-URL: Documentation, https://github.com/yourusername/markdown-pdf-converter#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/yourusername/markdown-pdf-converter
|
|
10
|
+
Project-URL: Issues, https://github.com/yourusername/markdown-pdf-converter/issues
|
|
11
|
+
Keywords: markdown,pdf,converter,chinese,reportlab
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Requires-Python: >=3.7
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: reportlab>=3.6.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Markdown PDF Converter
|
|
37
|
+
|
|
38
|
+
[](https://badge.fury.io/py/markdown-pdf-converter)
|
|
39
|
+
[](https://pypi.org/project/markdown-pdf-converter/)
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
|
|
42
|
+
A Python library to convert Markdown files to PDF with **Chinese support** and **intelligent code wrapping**.
|
|
43
|
+
|
|
44
|
+
## ✨ Features
|
|
45
|
+
|
|
46
|
+
- 📝 **Markdown to PDF**: Convert Markdown files to beautifully formatted PDF documents
|
|
47
|
+
- 🇨🇳 **Chinese Support**: Automatic Chinese font detection and rendering
|
|
48
|
+
- 💻 **Code Block Handling**: Smart formatting for code blocks with proper line wrapping
|
|
49
|
+
- 🎨 **Customizable Styles**: Multiple style presets (default, compact, large print)
|
|
50
|
+
- 🔧 **Flexible Configuration**: Customize fonts, margins, font sizes, and colors
|
|
51
|
+
- 🚀 **Command Line Interface**: Easy-to-use CLI for quick conversions
|
|
52
|
+
- 📦 **Pure Python**: No external dependencies except reportlab
|
|
53
|
+
|
|
54
|
+
## 📦 Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install markdown-pdf-converter
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Development Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/yourusername/markdown-pdf-converter.git
|
|
64
|
+
cd markdown-pdf-converter
|
|
65
|
+
pip install -e ".[dev]"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 🚀 Quick Start
|
|
69
|
+
|
|
70
|
+
### Command Line Usage
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Basic conversion
|
|
74
|
+
md2pdf input.md
|
|
75
|
+
|
|
76
|
+
# Specify output file
|
|
77
|
+
md2pdf input.md -o output.pdf
|
|
78
|
+
|
|
79
|
+
# Use compact style for dense content
|
|
80
|
+
md2pdf input.md --style compact
|
|
81
|
+
|
|
82
|
+
# Use custom font
|
|
83
|
+
md2pdf input.md --font /path/to/chinese/font.ttf
|
|
84
|
+
|
|
85
|
+
# Customize font sizes and margins
|
|
86
|
+
md2pdf input.md --title-size 18 --body-size 10 --margin 2.5
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Python API Usage
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from markdown_pdf_converter import MarkdownToPDFConverter
|
|
93
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
94
|
+
|
|
95
|
+
# Basic usage
|
|
96
|
+
converter = MarkdownToPDFConverter()
|
|
97
|
+
converter.convert("input.md", "output.pdf")
|
|
98
|
+
|
|
99
|
+
# With custom font
|
|
100
|
+
converter = MarkdownToPDFConverter(font_path="/path/to/font.ttf")
|
|
101
|
+
converter.convert("input.md", "output.pdf")
|
|
102
|
+
|
|
103
|
+
# With custom styles
|
|
104
|
+
styles = PDFStyles(
|
|
105
|
+
title_font_size=20,
|
|
106
|
+
body_font_size=11,
|
|
107
|
+
right_margin=2.5,
|
|
108
|
+
left_margin=2.5
|
|
109
|
+
)
|
|
110
|
+
converter = MarkdownToPDFConverter()
|
|
111
|
+
converter.convert("input.md", "output.pdf", **styles.to_dict())
|
|
112
|
+
|
|
113
|
+
# Use preset styles
|
|
114
|
+
converter = MarkdownToPDFConverter()
|
|
115
|
+
converter.convert("input.md", "output.pdf", **PDFStyles.compact().to_dict())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 📖 Supported Markdown Features
|
|
119
|
+
|
|
120
|
+
- ✅ Headers (H1, H2, H3)
|
|
121
|
+
- ✅ Bold and italic text
|
|
122
|
+
- ✅ Lists (ordered and unordered)
|
|
123
|
+
- ✅ Code blocks and inline code
|
|
124
|
+
- ✅ Blockquotes
|
|
125
|
+
- ✅ Links
|
|
126
|
+
- ✅ Horizontal rules
|
|
127
|
+
- ✅ Tables (simplified)
|
|
128
|
+
|
|
129
|
+
## 🎨 Style Presets
|
|
130
|
+
|
|
131
|
+
### Default Style
|
|
132
|
+
Standard formatting suitable for most documents.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
136
|
+
styles = PDFStyles.default()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Compact Style
|
|
140
|
+
Optimized for dense content like technical documentation.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
144
|
+
styles = PDFStyles.compact()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Large Print Style
|
|
148
|
+
Enhanced readability with larger fonts.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
152
|
+
styles = PDFStyles.large_print()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 🔧 Configuration Options
|
|
156
|
+
|
|
157
|
+
### PDFStyles Parameters
|
|
158
|
+
|
|
159
|
+
| Parameter | Type | Default | Description |
|
|
160
|
+
|-----------|------|---------|-------------|
|
|
161
|
+
| `page_size` | str | "A4" | Page size (A4, Letter, Legal) |
|
|
162
|
+
| `right_margin` | float | 2.0 | Right margin in cm |
|
|
163
|
+
| `left_margin` | float | 2.0 | Left margin in cm |
|
|
164
|
+
| `top_margin` | float | 2.0 | Top margin in cm |
|
|
165
|
+
| `bottom_margin` | float | 2.0 | Bottom margin in cm |
|
|
166
|
+
| `title_font_size` | int | 16 | H1 font size |
|
|
167
|
+
| `heading_font_size` | int | 13 | H2 font size |
|
|
168
|
+
| `subheading_font_size` | int | 11 | H3 font size |
|
|
169
|
+
| `body_font_size` | int | 9 | Body text font size |
|
|
170
|
+
| `code_font_size` | int | 8 | Code block font size |
|
|
171
|
+
|
|
172
|
+
## 🌐 Chinese Font Support
|
|
173
|
+
|
|
174
|
+
The library automatically detects and uses Chinese fonts from common system locations:
|
|
175
|
+
|
|
176
|
+
- **macOS**: PingFang, STHeiti, Hiragino Sans GB
|
|
177
|
+
- **Linux**: WQY Zenhei, WQY Microhei, Noto Sans CJK
|
|
178
|
+
- **Windows**: SimSun, Microsoft YaHei (add your font path manually)
|
|
179
|
+
|
|
180
|
+
### Custom Font
|
|
181
|
+
|
|
182
|
+
If automatic detection fails, specify a font path:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
converter = MarkdownToPDFConverter(font_path="/path/to/your/font.ttf")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 🧪 Testing
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Run tests
|
|
192
|
+
pytest
|
|
193
|
+
|
|
194
|
+
# Run tests with coverage
|
|
195
|
+
pytest --cov=markdown_pdf_converter
|
|
196
|
+
|
|
197
|
+
# Run linting
|
|
198
|
+
black markdown_pdf_converter/
|
|
199
|
+
flake8 markdown_pdf_converter/
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## 📁 Project Structure
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
markdown-pdf-converter/
|
|
206
|
+
├── markdown_pdf_converter/ # Main package
|
|
207
|
+
│ ├── __init__.py
|
|
208
|
+
│ ├── converter.py # Core conversion logic
|
|
209
|
+
│ ├── styles.py # Style configuration
|
|
210
|
+
│ └── cli.py # Command line interface
|
|
211
|
+
├── tests/ # Test files
|
|
212
|
+
├── examples/ # Example files
|
|
213
|
+
├── pyproject.toml # Package configuration
|
|
214
|
+
├── README.md # This file
|
|
215
|
+
└── LICENSE # MIT License
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 🤝 Contributing
|
|
219
|
+
|
|
220
|
+
1. Fork the repository
|
|
221
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
222
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
223
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
224
|
+
5. Open a Pull Request
|
|
225
|
+
|
|
226
|
+
## 📝 License
|
|
227
|
+
|
|
228
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
229
|
+
|
|
230
|
+
## 🐛 Issues
|
|
231
|
+
|
|
232
|
+
If you encounter any issues or have suggestions, please [open an issue](https://github.com/yourusername/markdown-pdf-converter/issues).
|
|
233
|
+
|
|
234
|
+
## 🙏 Acknowledgments
|
|
235
|
+
|
|
236
|
+
- Built with [ReportLab](https://www.reportlab.com/) - PDF generation library
|
|
237
|
+
- Inspired by the need for simple Markdown to PDF conversion with Chinese support
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
**Happy Converting!** 🎉
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Markdown PDF Converter
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/markdown-pdf-converter)
|
|
4
|
+
[](https://pypi.org/project/markdown-pdf-converter/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A Python library to convert Markdown files to PDF with **Chinese support** and **intelligent code wrapping**.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- 📝 **Markdown to PDF**: Convert Markdown files to beautifully formatted PDF documents
|
|
12
|
+
- 🇨🇳 **Chinese Support**: Automatic Chinese font detection and rendering
|
|
13
|
+
- 💻 **Code Block Handling**: Smart formatting for code blocks with proper line wrapping
|
|
14
|
+
- 🎨 **Customizable Styles**: Multiple style presets (default, compact, large print)
|
|
15
|
+
- 🔧 **Flexible Configuration**: Customize fonts, margins, font sizes, and colors
|
|
16
|
+
- 🚀 **Command Line Interface**: Easy-to-use CLI for quick conversions
|
|
17
|
+
- 📦 **Pure Python**: No external dependencies except reportlab
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install markdown-pdf-converter
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Development Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/yourusername/markdown-pdf-converter.git
|
|
29
|
+
cd markdown-pdf-converter
|
|
30
|
+
pip install -e ".[dev]"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start
|
|
34
|
+
|
|
35
|
+
### Command Line Usage
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Basic conversion
|
|
39
|
+
md2pdf input.md
|
|
40
|
+
|
|
41
|
+
# Specify output file
|
|
42
|
+
md2pdf input.md -o output.pdf
|
|
43
|
+
|
|
44
|
+
# Use compact style for dense content
|
|
45
|
+
md2pdf input.md --style compact
|
|
46
|
+
|
|
47
|
+
# Use custom font
|
|
48
|
+
md2pdf input.md --font /path/to/chinese/font.ttf
|
|
49
|
+
|
|
50
|
+
# Customize font sizes and margins
|
|
51
|
+
md2pdf input.md --title-size 18 --body-size 10 --margin 2.5
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Python API Usage
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from markdown_pdf_converter import MarkdownToPDFConverter
|
|
58
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
59
|
+
|
|
60
|
+
# Basic usage
|
|
61
|
+
converter = MarkdownToPDFConverter()
|
|
62
|
+
converter.convert("input.md", "output.pdf")
|
|
63
|
+
|
|
64
|
+
# With custom font
|
|
65
|
+
converter = MarkdownToPDFConverter(font_path="/path/to/font.ttf")
|
|
66
|
+
converter.convert("input.md", "output.pdf")
|
|
67
|
+
|
|
68
|
+
# With custom styles
|
|
69
|
+
styles = PDFStyles(
|
|
70
|
+
title_font_size=20,
|
|
71
|
+
body_font_size=11,
|
|
72
|
+
right_margin=2.5,
|
|
73
|
+
left_margin=2.5
|
|
74
|
+
)
|
|
75
|
+
converter = MarkdownToPDFConverter()
|
|
76
|
+
converter.convert("input.md", "output.pdf", **styles.to_dict())
|
|
77
|
+
|
|
78
|
+
# Use preset styles
|
|
79
|
+
converter = MarkdownToPDFConverter()
|
|
80
|
+
converter.convert("input.md", "output.pdf", **PDFStyles.compact().to_dict())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 📖 Supported Markdown Features
|
|
84
|
+
|
|
85
|
+
- ✅ Headers (H1, H2, H3)
|
|
86
|
+
- ✅ Bold and italic text
|
|
87
|
+
- ✅ Lists (ordered and unordered)
|
|
88
|
+
- ✅ Code blocks and inline code
|
|
89
|
+
- ✅ Blockquotes
|
|
90
|
+
- ✅ Links
|
|
91
|
+
- ✅ Horizontal rules
|
|
92
|
+
- ✅ Tables (simplified)
|
|
93
|
+
|
|
94
|
+
## 🎨 Style Presets
|
|
95
|
+
|
|
96
|
+
### Default Style
|
|
97
|
+
Standard formatting suitable for most documents.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
101
|
+
styles = PDFStyles.default()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Compact Style
|
|
105
|
+
Optimized for dense content like technical documentation.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
109
|
+
styles = PDFStyles.compact()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Large Print Style
|
|
113
|
+
Enhanced readability with larger fonts.
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
117
|
+
styles = PDFStyles.large_print()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 🔧 Configuration Options
|
|
121
|
+
|
|
122
|
+
### PDFStyles Parameters
|
|
123
|
+
|
|
124
|
+
| Parameter | Type | Default | Description |
|
|
125
|
+
|-----------|------|---------|-------------|
|
|
126
|
+
| `page_size` | str | "A4" | Page size (A4, Letter, Legal) |
|
|
127
|
+
| `right_margin` | float | 2.0 | Right margin in cm |
|
|
128
|
+
| `left_margin` | float | 2.0 | Left margin in cm |
|
|
129
|
+
| `top_margin` | float | 2.0 | Top margin in cm |
|
|
130
|
+
| `bottom_margin` | float | 2.0 | Bottom margin in cm |
|
|
131
|
+
| `title_font_size` | int | 16 | H1 font size |
|
|
132
|
+
| `heading_font_size` | int | 13 | H2 font size |
|
|
133
|
+
| `subheading_font_size` | int | 11 | H3 font size |
|
|
134
|
+
| `body_font_size` | int | 9 | Body text font size |
|
|
135
|
+
| `code_font_size` | int | 8 | Code block font size |
|
|
136
|
+
|
|
137
|
+
## 🌐 Chinese Font Support
|
|
138
|
+
|
|
139
|
+
The library automatically detects and uses Chinese fonts from common system locations:
|
|
140
|
+
|
|
141
|
+
- **macOS**: PingFang, STHeiti, Hiragino Sans GB
|
|
142
|
+
- **Linux**: WQY Zenhei, WQY Microhei, Noto Sans CJK
|
|
143
|
+
- **Windows**: SimSun, Microsoft YaHei (add your font path manually)
|
|
144
|
+
|
|
145
|
+
### Custom Font
|
|
146
|
+
|
|
147
|
+
If automatic detection fails, specify a font path:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
converter = MarkdownToPDFConverter(font_path="/path/to/your/font.ttf")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 🧪 Testing
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Run tests
|
|
157
|
+
pytest
|
|
158
|
+
|
|
159
|
+
# Run tests with coverage
|
|
160
|
+
pytest --cov=markdown_pdf_converter
|
|
161
|
+
|
|
162
|
+
# Run linting
|
|
163
|
+
black markdown_pdf_converter/
|
|
164
|
+
flake8 markdown_pdf_converter/
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 📁 Project Structure
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
markdown-pdf-converter/
|
|
171
|
+
├── markdown_pdf_converter/ # Main package
|
|
172
|
+
│ ├── __init__.py
|
|
173
|
+
│ ├── converter.py # Core conversion logic
|
|
174
|
+
│ ├── styles.py # Style configuration
|
|
175
|
+
│ └── cli.py # Command line interface
|
|
176
|
+
├── tests/ # Test files
|
|
177
|
+
├── examples/ # Example files
|
|
178
|
+
├── pyproject.toml # Package configuration
|
|
179
|
+
├── README.md # This file
|
|
180
|
+
└── LICENSE # MIT License
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 🤝 Contributing
|
|
184
|
+
|
|
185
|
+
1. Fork the repository
|
|
186
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
187
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
188
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
189
|
+
5. Open a Pull Request
|
|
190
|
+
|
|
191
|
+
## 📝 License
|
|
192
|
+
|
|
193
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
194
|
+
|
|
195
|
+
## 🐛 Issues
|
|
196
|
+
|
|
197
|
+
If you encounter any issues or have suggestions, please [open an issue](https://github.com/yourusername/markdown-pdf-converter/issues).
|
|
198
|
+
|
|
199
|
+
## 🙏 Acknowledgments
|
|
200
|
+
|
|
201
|
+
- Built with [ReportLab](https://www.reportlab.com/) - PDF generation library
|
|
202
|
+
- Inspired by the need for simple Markdown to PDF conversion with Chinese support
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
**Happy Converting!** 🎉
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Example usage of markdown-pdf-converter
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from markdown_pdf_converter import MarkdownToPDFConverter
|
|
8
|
+
from markdown_pdf_converter.styles import PDFStyles
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def basic_conversion():
|
|
12
|
+
"""Basic conversion example"""
|
|
13
|
+
converter = MarkdownToPDFConverter()
|
|
14
|
+
|
|
15
|
+
# Get the directory of this script
|
|
16
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
17
|
+
input_file = os.path.join(script_dir, "example.md")
|
|
18
|
+
output_file = os.path.join(script_dir, "example_basic.pdf")
|
|
19
|
+
|
|
20
|
+
converter.convert(input_file, output_file)
|
|
21
|
+
print(f"✓ Basic conversion complete: {output_file}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def compact_style_conversion():
|
|
25
|
+
"""Compact style conversion example"""
|
|
26
|
+
converter = MarkdownToPDFConverter()
|
|
27
|
+
|
|
28
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
29
|
+
input_file = os.path.join(script_dir, "example.md")
|
|
30
|
+
output_file = os.path.join(script_dir, "example_compact.pdf")
|
|
31
|
+
|
|
32
|
+
# Use compact style
|
|
33
|
+
styles = PDFStyles.compact()
|
|
34
|
+
converter.convert(input_file, output_file, **styles.to_dict())
|
|
35
|
+
print(f"✓ Compact style conversion complete: {output_file}")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def large_print_conversion():
|
|
39
|
+
"""Large print style conversion example"""
|
|
40
|
+
converter = MarkdownToPDFConverter()
|
|
41
|
+
|
|
42
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
43
|
+
input_file = os.path.join(script_dir, "example.md")
|
|
44
|
+
output_file = os.path.join(script_dir, "example_large.pdf")
|
|
45
|
+
|
|
46
|
+
# Use large print style
|
|
47
|
+
styles = PDFStyles.large_print()
|
|
48
|
+
converter.convert(input_file, output_file, **styles.to_dict())
|
|
49
|
+
print(f"✓ Large print conversion complete: {output_file}")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def custom_style_conversion():
|
|
53
|
+
"""Custom style conversion example"""
|
|
54
|
+
converter = MarkdownToPDFConverter()
|
|
55
|
+
|
|
56
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
57
|
+
input_file = os.path.join(script_dir, "example.md")
|
|
58
|
+
output_file = os.path.join(script_dir, "example_custom.pdf")
|
|
59
|
+
|
|
60
|
+
# Create custom styles
|
|
61
|
+
styles = PDFStyles(
|
|
62
|
+
title_font_size=20,
|
|
63
|
+
heading_font_size=16,
|
|
64
|
+
body_font_size=11,
|
|
65
|
+
code_font_size=9,
|
|
66
|
+
right_margin=2.5,
|
|
67
|
+
left_margin=2.5,
|
|
68
|
+
top_margin=2.5,
|
|
69
|
+
bottom_margin=2.5
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
converter.convert(input_file, output_file, **styles.to_dict())
|
|
73
|
+
print(f"✓ Custom style conversion complete: {output_file}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
print("Running Markdown to PDF Converter Examples...\n")
|
|
78
|
+
|
|
79
|
+
basic_conversion()
|
|
80
|
+
compact_style_conversion()
|
|
81
|
+
large_print_conversion()
|
|
82
|
+
custom_style_conversion()
|
|
83
|
+
|
|
84
|
+
print("\n✓ All examples completed!")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Markdown PDF Converter Example
|
|
2
|
+
|
|
3
|
+
This is an example Markdown file to demonstrate the conversion capabilities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Text Formatting
|
|
8
|
+
|
|
9
|
+
**Bold text** and *italic text* are supported.
|
|
10
|
+
|
|
11
|
+
### Lists
|
|
12
|
+
|
|
13
|
+
Unordered list:
|
|
14
|
+
- Item 1
|
|
15
|
+
- Item 2
|
|
16
|
+
- Item 3
|
|
17
|
+
|
|
18
|
+
Ordered list:
|
|
19
|
+
1. First item
|
|
20
|
+
2. Second item
|
|
21
|
+
3. Third item
|
|
22
|
+
|
|
23
|
+
### Code Blocks
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
def hello_world():
|
|
27
|
+
print("Hello, World!")
|
|
28
|
+
return True
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```java
|
|
32
|
+
public class HelloWorld {
|
|
33
|
+
public static void main(String[] args) {
|
|
34
|
+
System.out.println("Hello, World!");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Links
|
|
40
|
+
|
|
41
|
+
Visit [GitHub](https://github.com) for more information.
|
|
42
|
+
|
|
43
|
+
### Blockquotes
|
|
44
|
+
|
|
45
|
+
> This is a blockquote.
|
|
46
|
+
> It can span multiple lines.
|
|
47
|
+
|
|
48
|
+
### Tables
|
|
49
|
+
|
|
50
|
+
| Feature | Supported |
|
|
51
|
+
|---------|-----------|
|
|
52
|
+
| Headers | Yes |
|
|
53
|
+
| Lists | Yes |
|
|
54
|
+
| Code | Yes |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Chinese Support Test
|
|
59
|
+
|
|
60
|
+
这是一个中文测试段落。
|
|
61
|
+
|
|
62
|
+
### 中文列表演示
|
|
63
|
+
|
|
64
|
+
- 第一项
|
|
65
|
+
- 第二项
|
|
66
|
+
- 第三项
|
|
67
|
+
|
|
68
|
+
### 中文代码示例
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# 中文注释示例
|
|
72
|
+
def greet(name):
|
|
73
|
+
print(f"你好,{name}!")
|
|
74
|
+
return True
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**结束**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Markdown to PDF Converter
|
|
3
|
+
|
|
4
|
+
A Python library to convert Markdown files to PDF with Chinese support.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .converter import MarkdownToPDFConverter
|
|
8
|
+
from .styles import PDFStyles
|
|
9
|
+
|
|
10
|
+
__version__ = "1.0.0"
|
|
11
|
+
__author__ = "Your Name"
|
|
12
|
+
__email__ = "your.email@example.com"
|
|
13
|
+
|
|
14
|
+
__all__ = ["MarkdownToPDFConverter", "PDFStyles"]
|