markdown-pdf 1.3.2__tar.gz → 1.3.4__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-1.3.4/PKG-INFO +163 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/README.md +21 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/markdown_pdf/__init__.py +5 -2
- markdown_pdf-1.3.4/markdown_pdf.egg-info/PKG-INFO +163 -0
- markdown_pdf-1.3.4/markdown_pdf.egg-info/requires.txt +9 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/setup.cfg +4 -3
- markdown_pdf-1.3.2/PKG-INFO +0 -143
- markdown_pdf-1.3.2/markdown_pdf.egg-info/PKG-INFO +0 -143
- markdown_pdf-1.3.2/markdown_pdf.egg-info/requires.txt +0 -2
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/LICENSE +0 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/MANIFEST.in +0 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/markdown_pdf.egg-info/SOURCES.txt +0 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/markdown_pdf.egg-info/dependency_links.txt +0 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/markdown_pdf.egg-info/top_level.txt +0 -0
- {markdown_pdf-1.3.2 → markdown_pdf-1.3.4}/pyproject.toml +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: markdown_pdf
|
|
3
|
+
Version: 1.3.4
|
|
4
|
+
Summary: Markdown to pdf renderer
|
|
5
|
+
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
|
+
Author: Vitaly Bogomolov
|
|
7
|
+
Author-email: mail@vitaly-bogomolov.ru
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
10
|
+
Description: # Module markdown-pdf
|
|
11
|
+
|
|
12
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
13
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
14
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
15
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
16
|
+
[](https://pypistats.org/packages/markdown-pdf)
|
|
17
|
+
|
|
18
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
19
|
+
|
|
20
|
+
When creating a PDF file you can:
|
|
21
|
+
|
|
22
|
+
- Use `UTF-8` encoded text in `markdown` in any language
|
|
23
|
+
- Embed images used in `markdown`
|
|
24
|
+
- Break text into pages in the desired order
|
|
25
|
+
- Create a TableOfContents (bookmarks) from markdown headings
|
|
26
|
+
- Tune the necessary elements using your CSS code
|
|
27
|
+
- Use different page sizes within single pdf
|
|
28
|
+
- Create tables in `markdown`
|
|
29
|
+
|
|
30
|
+
The module utilizes the functions of two great libraries.
|
|
31
|
+
|
|
32
|
+
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
33
|
+
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install markdown-pdf
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from markdown_pdf import MarkdownPdf
|
|
47
|
+
|
|
48
|
+
pdf = MarkdownPdf(toc_level=2)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Add the first section to the pdf. The title is not included in the table of contents.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from markdown_pdf import Section
|
|
55
|
+
|
|
56
|
+
pdf.add_section(Section("# Title\n", toc=False))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Add a second section. In the pdf file it starts on a new page.
|
|
60
|
+
The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
pdf.add_section(
|
|
64
|
+
Section("# Head1\n\n\n\nbody\n"),
|
|
65
|
+
user_css="h1 {text-align:center;}"
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Add a third section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
70
|
+
The section has landscape orientation of A4 pages.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
pdf.add_section(Section("## Head2\n\n### Head3\n\n", paper_size="A4-L"))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a fourth section with a table.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
|
|
80
|
+
text = """# Section with Table
|
|
81
|
+
|
|
82
|
+
|TableHeader1|TableHeader2|
|
|
83
|
+
|--|--|
|
|
84
|
+
|Text1|Text2|
|
|
85
|
+
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
89
|
+
|
|
90
|
+
pdf.add_section(Section(text), user_css=css)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Set the properties of the pdf document.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
pdf.meta["title"] = "User Guide"
|
|
97
|
+
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Save to file.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
pdf.save("guide.pdf")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+

|
|
107
|
+
|
|
108
|
+
## Settings and options
|
|
109
|
+
|
|
110
|
+
The `Section` class defines a portion of `markdown` data,
|
|
111
|
+
which is processed according to the same rules.
|
|
112
|
+
The next `Section` data starts on a new page.
|
|
113
|
+
|
|
114
|
+
The `Section` class can set the following attributes.
|
|
115
|
+
|
|
116
|
+
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
117
|
+
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
118
|
+
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
119
|
+
- borders: size of borders. Default (36, 36, -36, -36).
|
|
120
|
+
|
|
121
|
+
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
122
|
+
|
|
123
|
+
- `creationDate`: current date
|
|
124
|
+
- `modDate`: current date
|
|
125
|
+
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
126
|
+
- `producer`: ""
|
|
127
|
+
- `title`: ""
|
|
128
|
+
- `author`: ""
|
|
129
|
+
- `subject`: ""
|
|
130
|
+
- `keywords`: ""
|
|
131
|
+
|
|
132
|
+
## Example
|
|
133
|
+
|
|
134
|
+
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
135
|
+
This [Python script](makepdf.py) was used to create the PDF file.
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git clone git@github.com:vb64/markdown-pdf.git
|
|
141
|
+
cd markdown-pdf
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
With Python > 3.8
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
make setup PYTHON_BIN=/path/to/python3
|
|
148
|
+
make tests
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
With Python 3.8
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
155
|
+
make tests
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Platform: UNKNOWN
|
|
159
|
+
Classifier: Programming Language :: Python :: 3
|
|
160
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
161
|
+
Classifier: Operating System :: OS Independent
|
|
162
|
+
Requires-Python: >=3.8
|
|
163
|
+
Description-Content-Type: text/markdown
|
|
@@ -124,3 +124,24 @@ The following document properties are available for assignment (dictionary `Mark
|
|
|
124
124
|
|
|
125
125
|
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
126
126
|
This [Python script](makepdf.py) was used to create the PDF file.
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git clone git@github.com:vb64/markdown-pdf.git
|
|
132
|
+
cd markdown-pdf
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
With Python > 3.8
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
make setup PYTHON_BIN=/path/to/python3
|
|
139
|
+
make tests
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
With Python 3.8
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
146
|
+
make tests
|
|
147
|
+
```
|
|
@@ -69,11 +69,12 @@ class MarkdownPdf:
|
|
|
69
69
|
elpos.rect[1], # top of written rectangle (use for TOC)
|
|
70
70
|
))
|
|
71
71
|
|
|
72
|
-
def add_section(self, section: Section, user_css: typing.Optional[str] = None) ->
|
|
72
|
+
def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> str:
|
|
73
73
|
"""Add markdown section to pdf."""
|
|
74
74
|
rect = fitz.paper_rect(section.paper_size)
|
|
75
75
|
where = rect + section.borders
|
|
76
|
-
|
|
76
|
+
html = self.m_d.render(section.text)
|
|
77
|
+
story = fitz.Story(html=html, archive=section.root, user_css=user_css)
|
|
77
78
|
more = 1
|
|
78
79
|
while more: # loop outputting the story
|
|
79
80
|
self.page += 1
|
|
@@ -83,6 +84,8 @@ class MarkdownPdf:
|
|
|
83
84
|
story.draw(device)
|
|
84
85
|
self.writer.end_page()
|
|
85
86
|
|
|
87
|
+
return html
|
|
88
|
+
|
|
86
89
|
def save(self, file_name: typing.Union[str, pathlib.Path]) -> None:
|
|
87
90
|
"""Save pdf to file."""
|
|
88
91
|
self.writer.close()
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: markdown-pdf
|
|
3
|
+
Version: 1.3.4
|
|
4
|
+
Summary: Markdown to pdf renderer
|
|
5
|
+
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
|
+
Author: Vitaly Bogomolov
|
|
7
|
+
Author-email: mail@vitaly-bogomolov.ru
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
10
|
+
Description: # Module markdown-pdf
|
|
11
|
+
|
|
12
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
13
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
14
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
15
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
16
|
+
[](https://pypistats.org/packages/markdown-pdf)
|
|
17
|
+
|
|
18
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
19
|
+
|
|
20
|
+
When creating a PDF file you can:
|
|
21
|
+
|
|
22
|
+
- Use `UTF-8` encoded text in `markdown` in any language
|
|
23
|
+
- Embed images used in `markdown`
|
|
24
|
+
- Break text into pages in the desired order
|
|
25
|
+
- Create a TableOfContents (bookmarks) from markdown headings
|
|
26
|
+
- Tune the necessary elements using your CSS code
|
|
27
|
+
- Use different page sizes within single pdf
|
|
28
|
+
- Create tables in `markdown`
|
|
29
|
+
|
|
30
|
+
The module utilizes the functions of two great libraries.
|
|
31
|
+
|
|
32
|
+
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
33
|
+
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install markdown-pdf
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from markdown_pdf import MarkdownPdf
|
|
47
|
+
|
|
48
|
+
pdf = MarkdownPdf(toc_level=2)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Add the first section to the pdf. The title is not included in the table of contents.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from markdown_pdf import Section
|
|
55
|
+
|
|
56
|
+
pdf.add_section(Section("# Title\n", toc=False))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Add a second section. In the pdf file it starts on a new page.
|
|
60
|
+
The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
pdf.add_section(
|
|
64
|
+
Section("# Head1\n\n\n\nbody\n"),
|
|
65
|
+
user_css="h1 {text-align:center;}"
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Add a third section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
70
|
+
The section has landscape orientation of A4 pages.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
pdf.add_section(Section("## Head2\n\n### Head3\n\n", paper_size="A4-L"))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a fourth section with a table.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
|
|
80
|
+
text = """# Section with Table
|
|
81
|
+
|
|
82
|
+
|TableHeader1|TableHeader2|
|
|
83
|
+
|--|--|
|
|
84
|
+
|Text1|Text2|
|
|
85
|
+
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
89
|
+
|
|
90
|
+
pdf.add_section(Section(text), user_css=css)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Set the properties of the pdf document.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
pdf.meta["title"] = "User Guide"
|
|
97
|
+
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Save to file.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
pdf.save("guide.pdf")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+

|
|
107
|
+
|
|
108
|
+
## Settings and options
|
|
109
|
+
|
|
110
|
+
The `Section` class defines a portion of `markdown` data,
|
|
111
|
+
which is processed according to the same rules.
|
|
112
|
+
The next `Section` data starts on a new page.
|
|
113
|
+
|
|
114
|
+
The `Section` class can set the following attributes.
|
|
115
|
+
|
|
116
|
+
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
117
|
+
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
118
|
+
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
119
|
+
- borders: size of borders. Default (36, 36, -36, -36).
|
|
120
|
+
|
|
121
|
+
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
122
|
+
|
|
123
|
+
- `creationDate`: current date
|
|
124
|
+
- `modDate`: current date
|
|
125
|
+
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
126
|
+
- `producer`: ""
|
|
127
|
+
- `title`: ""
|
|
128
|
+
- `author`: ""
|
|
129
|
+
- `subject`: ""
|
|
130
|
+
- `keywords`: ""
|
|
131
|
+
|
|
132
|
+
## Example
|
|
133
|
+
|
|
134
|
+
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
135
|
+
This [Python script](makepdf.py) was used to create the PDF file.
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git clone git@github.com:vb64/markdown-pdf.git
|
|
141
|
+
cd markdown-pdf
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
With Python > 3.8
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
make setup PYTHON_BIN=/path/to/python3
|
|
148
|
+
make tests
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
With Python 3.8
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
155
|
+
make tests
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Platform: UNKNOWN
|
|
159
|
+
Classifier: Programming Language :: Python :: 3
|
|
160
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
161
|
+
Classifier: Operating System :: OS Independent
|
|
162
|
+
Requires-Python: >=3.8
|
|
163
|
+
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = markdown_pdf
|
|
3
|
-
version = 1.3.
|
|
3
|
+
version = 1.3.4
|
|
4
4
|
author = Vitaly Bogomolov
|
|
5
5
|
author_email = mail@vitaly-bogomolov.ru
|
|
6
6
|
description = Markdown to pdf renderer
|
|
@@ -19,8 +19,9 @@ package_dir =
|
|
|
19
19
|
packages = markdown_pdf
|
|
20
20
|
python_requires = >=3.8
|
|
21
21
|
install_requires =
|
|
22
|
-
PyMuPDF==1.24.
|
|
23
|
-
|
|
22
|
+
PyMuPDF==1.24.6; python_version<"3.9"
|
|
23
|
+
PyMuPDF==1.25.3; python_version>"3.8"
|
|
24
|
+
markdown-it-py==3.0.0; python_version>="3.8"
|
|
24
25
|
|
|
25
26
|
[egg_info]
|
|
26
27
|
tag_build =
|
markdown_pdf-1.3.2/PKG-INFO
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: markdown_pdf
|
|
3
|
-
Version: 1.3.2
|
|
4
|
-
Summary: Markdown to pdf renderer
|
|
5
|
-
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
|
-
Author: Vitaly Bogomolov
|
|
7
|
-
Author-email: mail@vitaly-bogomolov.ru
|
|
8
|
-
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.8
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: PyMuPDF==1.24.2
|
|
16
|
-
Requires-Dist: markdown-it-py==3.0.0
|
|
17
|
-
|
|
18
|
-
# Module markdown-pdf
|
|
19
|
-
|
|
20
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
21
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
22
|
-
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
23
|
-
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
24
|
-
[](https://pypistats.org/packages/markdown-pdf)
|
|
25
|
-
|
|
26
|
-
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
27
|
-
|
|
28
|
-
When creating a PDF file you can:
|
|
29
|
-
|
|
30
|
-
- Use `UTF-8` encoded text in `markdown` in any language
|
|
31
|
-
- Embed images used in `markdown`
|
|
32
|
-
- Break text into pages in the desired order
|
|
33
|
-
- Create a TableOfContents (bookmarks) from markdown headings
|
|
34
|
-
- Tune the necessary elements using your CSS code
|
|
35
|
-
- Use different page sizes within single pdf
|
|
36
|
-
- Create tables in `markdown`
|
|
37
|
-
|
|
38
|
-
The module utilizes the functions of two great libraries.
|
|
39
|
-
|
|
40
|
-
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
41
|
-
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install markdown-pdf
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Usage
|
|
50
|
-
|
|
51
|
-
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
from markdown_pdf import MarkdownPdf
|
|
55
|
-
|
|
56
|
-
pdf = MarkdownPdf(toc_level=2)
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Add the first section to the pdf. The title is not included in the table of contents.
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from markdown_pdf import Section
|
|
63
|
-
|
|
64
|
-
pdf.add_section(Section("# Title\n", toc=False))
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Add a second section. In the pdf file it starts on a new page.
|
|
68
|
-
The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
|
|
69
|
-
|
|
70
|
-
```python
|
|
71
|
-
pdf.add_section(
|
|
72
|
-
Section("# Head1\n\n\n\nbody\n"),
|
|
73
|
-
user_css="h1 {text-align:center;}"
|
|
74
|
-
)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Add a third section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
78
|
-
The section has landscape orientation of A4 pages.
|
|
79
|
-
|
|
80
|
-
```python
|
|
81
|
-
pdf.add_section(Section("## Head2\n\n### Head3\n\n", paper_size="A4-L"))
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Add a fourth section with a table.
|
|
85
|
-
|
|
86
|
-
```python
|
|
87
|
-
|
|
88
|
-
text = """# Section with Table
|
|
89
|
-
|
|
90
|
-
|TableHeader1|TableHeader2|
|
|
91
|
-
|--|--|
|
|
92
|
-
|Text1|Text2|
|
|
93
|
-
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
94
|
-
"""
|
|
95
|
-
|
|
96
|
-
css = "table, th, td {border: 1px solid black;}"
|
|
97
|
-
|
|
98
|
-
pdf.add_section(Section(text), user_css=css)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Set the properties of the pdf document.
|
|
102
|
-
|
|
103
|
-
```python
|
|
104
|
-
pdf.meta["title"] = "User Guide"
|
|
105
|
-
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Save to file.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
pdf.save("guide.pdf")
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-

|
|
115
|
-
|
|
116
|
-
## Settings and options
|
|
117
|
-
|
|
118
|
-
The `Section` class defines a portion of `markdown` data,
|
|
119
|
-
which is processed according to the same rules.
|
|
120
|
-
The next `Section` data starts on a new page.
|
|
121
|
-
|
|
122
|
-
The `Section` class can set the following attributes.
|
|
123
|
-
|
|
124
|
-
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
125
|
-
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
126
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
127
|
-
- borders: size of borders. Default (36, 36, -36, -36).
|
|
128
|
-
|
|
129
|
-
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
130
|
-
|
|
131
|
-
- `creationDate`: current date
|
|
132
|
-
- `modDate`: current date
|
|
133
|
-
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
134
|
-
- `producer`: ""
|
|
135
|
-
- `title`: ""
|
|
136
|
-
- `author`: ""
|
|
137
|
-
- `subject`: ""
|
|
138
|
-
- `keywords`: ""
|
|
139
|
-
|
|
140
|
-
## Example
|
|
141
|
-
|
|
142
|
-
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
143
|
-
This [Python script](makepdf.py) was used to create the PDF file.
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: markdown_pdf
|
|
3
|
-
Version: 1.3.2
|
|
4
|
-
Summary: Markdown to pdf renderer
|
|
5
|
-
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
|
-
Author: Vitaly Bogomolov
|
|
7
|
-
Author-email: mail@vitaly-bogomolov.ru
|
|
8
|
-
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.8
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: PyMuPDF==1.24.2
|
|
16
|
-
Requires-Dist: markdown-it-py==3.0.0
|
|
17
|
-
|
|
18
|
-
# Module markdown-pdf
|
|
19
|
-
|
|
20
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
21
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
22
|
-
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
23
|
-
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
24
|
-
[](https://pypistats.org/packages/markdown-pdf)
|
|
25
|
-
|
|
26
|
-
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
27
|
-
|
|
28
|
-
When creating a PDF file you can:
|
|
29
|
-
|
|
30
|
-
- Use `UTF-8` encoded text in `markdown` in any language
|
|
31
|
-
- Embed images used in `markdown`
|
|
32
|
-
- Break text into pages in the desired order
|
|
33
|
-
- Create a TableOfContents (bookmarks) from markdown headings
|
|
34
|
-
- Tune the necessary elements using your CSS code
|
|
35
|
-
- Use different page sizes within single pdf
|
|
36
|
-
- Create tables in `markdown`
|
|
37
|
-
|
|
38
|
-
The module utilizes the functions of two great libraries.
|
|
39
|
-
|
|
40
|
-
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
41
|
-
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install markdown-pdf
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Usage
|
|
50
|
-
|
|
51
|
-
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
from markdown_pdf import MarkdownPdf
|
|
55
|
-
|
|
56
|
-
pdf = MarkdownPdf(toc_level=2)
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Add the first section to the pdf. The title is not included in the table of contents.
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from markdown_pdf import Section
|
|
63
|
-
|
|
64
|
-
pdf.add_section(Section("# Title\n", toc=False))
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Add a second section. In the pdf file it starts on a new page.
|
|
68
|
-
The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
|
|
69
|
-
|
|
70
|
-
```python
|
|
71
|
-
pdf.add_section(
|
|
72
|
-
Section("# Head1\n\n\n\nbody\n"),
|
|
73
|
-
user_css="h1 {text-align:center;}"
|
|
74
|
-
)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Add a third section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
78
|
-
The section has landscape orientation of A4 pages.
|
|
79
|
-
|
|
80
|
-
```python
|
|
81
|
-
pdf.add_section(Section("## Head2\n\n### Head3\n\n", paper_size="A4-L"))
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Add a fourth section with a table.
|
|
85
|
-
|
|
86
|
-
```python
|
|
87
|
-
|
|
88
|
-
text = """# Section with Table
|
|
89
|
-
|
|
90
|
-
|TableHeader1|TableHeader2|
|
|
91
|
-
|--|--|
|
|
92
|
-
|Text1|Text2|
|
|
93
|
-
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
94
|
-
"""
|
|
95
|
-
|
|
96
|
-
css = "table, th, td {border: 1px solid black;}"
|
|
97
|
-
|
|
98
|
-
pdf.add_section(Section(text), user_css=css)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Set the properties of the pdf document.
|
|
102
|
-
|
|
103
|
-
```python
|
|
104
|
-
pdf.meta["title"] = "User Guide"
|
|
105
|
-
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Save to file.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
pdf.save("guide.pdf")
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-

|
|
115
|
-
|
|
116
|
-
## Settings and options
|
|
117
|
-
|
|
118
|
-
The `Section` class defines a portion of `markdown` data,
|
|
119
|
-
which is processed according to the same rules.
|
|
120
|
-
The next `Section` data starts on a new page.
|
|
121
|
-
|
|
122
|
-
The `Section` class can set the following attributes.
|
|
123
|
-
|
|
124
|
-
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
125
|
-
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
126
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
127
|
-
- borders: size of borders. Default (36, 36, -36, -36).
|
|
128
|
-
|
|
129
|
-
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
130
|
-
|
|
131
|
-
- `creationDate`: current date
|
|
132
|
-
- `modDate`: current date
|
|
133
|
-
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
134
|
-
- `producer`: ""
|
|
135
|
-
- `title`: ""
|
|
136
|
-
- `author`: ""
|
|
137
|
-
- `subject`: ""
|
|
138
|
-
- `keywords`: ""
|
|
139
|
-
|
|
140
|
-
## Example
|
|
141
|
-
|
|
142
|
-
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
143
|
-
This [Python script](makepdf.py) was used to create the PDF file.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|