markdown-pdf 1.6__tar.gz → 1.7__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.7/PKG-INFO +175 -0
- {markdown_pdf-1.6 → markdown_pdf-1.7}/README.md +2 -14
- {markdown_pdf-1.6 → markdown_pdf-1.7}/markdown_pdf/__init__.py +10 -3
- markdown_pdf-1.7/markdown_pdf/py.typed +0 -0
- markdown_pdf-1.7/markdown_pdf.egg-info/PKG-INFO +175 -0
- {markdown_pdf-1.6 → markdown_pdf-1.7}/markdown_pdf.egg-info/SOURCES.txt +1 -1
- {markdown_pdf-1.6 → markdown_pdf-1.7}/markdown_pdf.egg-info/requires.txt +8 -0
- markdown_pdf-1.7/pyproject.toml +47 -0
- markdown_pdf-1.7/setup.cfg +4 -0
- markdown_pdf-1.6/PKG-INFO +0 -178
- markdown_pdf-1.6/markdown_pdf.egg-info/PKG-INFO +0 -178
- markdown_pdf-1.6/pyproject.toml +0 -6
- markdown_pdf-1.6/setup.cfg +0 -29
- {markdown_pdf-1.6 → markdown_pdf-1.7}/LICENSE +0 -0
- {markdown_pdf-1.6 → markdown_pdf-1.7}/MANIFEST.in +0 -0
- {markdown_pdf-1.6 → markdown_pdf-1.7}/markdown_pdf.egg-info/dependency_links.txt +0 -0
- {markdown_pdf-1.6 → markdown_pdf-1.7}/markdown_pdf.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: markdown_pdf
|
|
3
|
+
Version: 1.7
|
|
4
|
+
Summary: Markdown to pdf renderer
|
|
5
|
+
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
|
+
License: GNU Affero General Public License v3
|
|
7
|
+
Project-URL: Homepage, https://github.com/vb64/markdown-pdf
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
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.6; python_version < "3.9"
|
|
16
|
+
Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
|
|
17
|
+
Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: flake8; extra == "dev"
|
|
20
|
+
Requires-Dist: pylint; extra == "dev"
|
|
21
|
+
Requires-Dist: pydocstyle; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
24
|
+
Requires-Dist: codacy-coverage; extra == "dev"
|
|
25
|
+
|
|
26
|
+
# Module markdown-pdf
|
|
27
|
+
|
|
28
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
29
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
30
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
31
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
32
|
+
[](https://pypistats.org/packages/markdown-pdf)
|
|
33
|
+
|
|
34
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
35
|
+
|
|
36
|
+
When creating a PDF file you can:
|
|
37
|
+
|
|
38
|
+
- Use `UTF-8` encoded text in `markdown` in any language
|
|
39
|
+
- Embed images used in `markdown`
|
|
40
|
+
- Break text into pages in the desired order
|
|
41
|
+
- Create a TableOfContents (bookmarks) from markdown headings
|
|
42
|
+
- Tune the necessary elements using your CSS code
|
|
43
|
+
- Use different page sizes within single pdf
|
|
44
|
+
- Create tables in `markdown`
|
|
45
|
+
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
46
|
+
|
|
47
|
+
The module utilizes the functions of two great libraries.
|
|
48
|
+
|
|
49
|
+
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
50
|
+
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install markdown-pdf
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from markdown_pdf import MarkdownPdf
|
|
64
|
+
|
|
65
|
+
pdf = MarkdownPdf(toc_level=2, optimize=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Add the first section to the pdf. The title is not included in the table of contents.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from markdown_pdf import Section
|
|
72
|
+
|
|
73
|
+
pdf.add_section(Section("# Title\n", toc=False))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a second section with external and internal hyperlinks.
|
|
77
|
+
In the pdf file it starts on a new page.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
text = """# Section with links
|
|
81
|
+
|
|
82
|
+
- [External link](https://github.com/vb64/markdown-pdf)
|
|
83
|
+
- [Internal link to Head1](#head1)
|
|
84
|
+
- [Internal link to Head3](#head3)
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
pdf.add_section(Section(text))
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Add a third section.
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
pdf.add_section(
|
|
95
|
+
Section("# <a name='head1'></a>Head1\n\n\n\nbody\n"),
|
|
96
|
+
user_css="h1 {text-align:center;}"
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
101
|
+
The section has landscape orientation of A4 pages.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Add a section with a table.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
|
|
111
|
+
text = """# Section with Table
|
|
112
|
+
|
|
113
|
+
|TableHeader1|TableHeader2|
|
|
114
|
+
|--|--|
|
|
115
|
+
|Text1|Text2|
|
|
116
|
+
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
120
|
+
|
|
121
|
+
pdf.add_section(Section(text), user_css=css)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Set the properties of the pdf document.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
pdf.meta["title"] = "User Guide"
|
|
128
|
+
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Save to file.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
pdf.save("guide.pdf")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
## Settings and options
|
|
140
|
+
|
|
141
|
+
The `Section` class defines a portion of `markdown` data,
|
|
142
|
+
which is processed according to the same rules.
|
|
143
|
+
The next `Section` data starts on a new page.
|
|
144
|
+
|
|
145
|
+
The `Section` class can set the following attributes.
|
|
146
|
+
|
|
147
|
+
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
148
|
+
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
149
|
+
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
150
|
+
- borders: size of borders. Default (36, 36, -36, -36).
|
|
151
|
+
|
|
152
|
+
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
153
|
+
|
|
154
|
+
- `creationDate`: current date
|
|
155
|
+
- `modDate`: current date
|
|
156
|
+
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
157
|
+
- `producer`: ""
|
|
158
|
+
- `title`: ""
|
|
159
|
+
- `author`: ""
|
|
160
|
+
- `subject`: ""
|
|
161
|
+
- `keywords`: ""
|
|
162
|
+
|
|
163
|
+
## Example
|
|
164
|
+
|
|
165
|
+
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
166
|
+
This [Python script](makepdf.py) was used to create the PDF file.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
git clone git@github.com:vb64/markdown-pdf.git
|
|
172
|
+
cd markdown-pdf
|
|
173
|
+
make setup PYTHON_BIN=/path/to/python3
|
|
174
|
+
make tests
|
|
175
|
+
```
|
|
@@ -32,12 +32,12 @@ pip install markdown-pdf
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
-
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
35
|
+
Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
|
|
36
36
|
|
|
37
37
|
```python
|
|
38
38
|
from markdown_pdf import MarkdownPdf
|
|
39
39
|
|
|
40
|
-
pdf = MarkdownPdf(toc_level=2)
|
|
40
|
+
pdf = MarkdownPdf(toc_level=2, optimize=True)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Add the first section to the pdf. The title is not included in the table of contents.
|
|
@@ -145,18 +145,6 @@ This [Python script](makepdf.py) was used to create the PDF file.
|
|
|
145
145
|
```bash
|
|
146
146
|
git clone git@github.com:vb64/markdown-pdf.git
|
|
147
147
|
cd markdown-pdf
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
With Python > 3.8
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
148
|
make setup PYTHON_BIN=/path/to/python3
|
|
154
149
|
make tests
|
|
155
150
|
```
|
|
156
|
-
|
|
157
|
-
With Python 3.8
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
161
|
-
make tests
|
|
162
|
-
```
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import io
|
|
3
3
|
import typing
|
|
4
4
|
import pathlib
|
|
5
|
+
|
|
6
|
+
|
|
5
7
|
from markdown_it import MarkdownIt
|
|
6
8
|
import fitz
|
|
7
9
|
|
|
@@ -15,7 +17,7 @@ class Section:
|
|
|
15
17
|
toc: bool = True,
|
|
16
18
|
root: str = ".",
|
|
17
19
|
paper_size: str = "A4",
|
|
18
|
-
borders:
|
|
20
|
+
borders: typing.Tuple[int, int, int, int] = (36, 36, -36, -36)
|
|
19
21
|
):
|
|
20
22
|
"""Create md section with given properties."""
|
|
21
23
|
self.text = text
|
|
@@ -40,7 +42,7 @@ class MarkdownPdf:
|
|
|
40
42
|
"keywords": None,
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
def __init__(self, toc_level: int = 6, mode: str = 'commonmark'):
|
|
45
|
+
def __init__(self, toc_level: int = 6, mode: str = 'commonmark', optimize: bool = False):
|
|
44
46
|
"""Create md -> pdf converter with given TOC level and mode of md parsing."""
|
|
45
47
|
self.toc_level = toc_level
|
|
46
48
|
self.toc = []
|
|
@@ -49,6 +51,8 @@ class MarkdownPdf:
|
|
|
49
51
|
# https://markdown-it-py.readthedocs.io/en/latest/using.html#quick-start
|
|
50
52
|
self.m_d = (MarkdownIt(mode).enable('table')) # Enable support for tables
|
|
51
53
|
|
|
54
|
+
self.optimize = optimize
|
|
55
|
+
|
|
52
56
|
self.out_file = io.BytesIO()
|
|
53
57
|
self.writer = fitz.DocumentWriter(self.out_file)
|
|
54
58
|
self.page_num = 0
|
|
@@ -98,5 +102,8 @@ class MarkdownPdf:
|
|
|
98
102
|
doc.set_metadata(self.meta)
|
|
99
103
|
if self.toc_level > 0:
|
|
100
104
|
doc.set_toc(self.toc)
|
|
101
|
-
|
|
105
|
+
if self.optimize:
|
|
106
|
+
doc.ez_save(file_name)
|
|
107
|
+
else:
|
|
108
|
+
doc.save(file_name)
|
|
102
109
|
doc.close()
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: markdown_pdf
|
|
3
|
+
Version: 1.7
|
|
4
|
+
Summary: Markdown to pdf renderer
|
|
5
|
+
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
|
+
License: GNU Affero General Public License v3
|
|
7
|
+
Project-URL: Homepage, https://github.com/vb64/markdown-pdf
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
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.6; python_version < "3.9"
|
|
16
|
+
Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
|
|
17
|
+
Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: flake8; extra == "dev"
|
|
20
|
+
Requires-Dist: pylint; extra == "dev"
|
|
21
|
+
Requires-Dist: pydocstyle; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
24
|
+
Requires-Dist: codacy-coverage; extra == "dev"
|
|
25
|
+
|
|
26
|
+
# Module markdown-pdf
|
|
27
|
+
|
|
28
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
29
|
+
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
30
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
31
|
+
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
32
|
+
[](https://pypistats.org/packages/markdown-pdf)
|
|
33
|
+
|
|
34
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
|
|
35
|
+
|
|
36
|
+
When creating a PDF file you can:
|
|
37
|
+
|
|
38
|
+
- Use `UTF-8` encoded text in `markdown` in any language
|
|
39
|
+
- Embed images used in `markdown`
|
|
40
|
+
- Break text into pages in the desired order
|
|
41
|
+
- Create a TableOfContents (bookmarks) from markdown headings
|
|
42
|
+
- Tune the necessary elements using your CSS code
|
|
43
|
+
- Use different page sizes within single pdf
|
|
44
|
+
- Create tables in `markdown`
|
|
45
|
+
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
46
|
+
|
|
47
|
+
The module utilizes the functions of two great libraries.
|
|
48
|
+
|
|
49
|
+
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
50
|
+
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install markdown-pdf
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from markdown_pdf import MarkdownPdf
|
|
64
|
+
|
|
65
|
+
pdf = MarkdownPdf(toc_level=2, optimize=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Add the first section to the pdf. The title is not included in the table of contents.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from markdown_pdf import Section
|
|
72
|
+
|
|
73
|
+
pdf.add_section(Section("# Title\n", toc=False))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a second section with external and internal hyperlinks.
|
|
77
|
+
In the pdf file it starts on a new page.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
text = """# Section with links
|
|
81
|
+
|
|
82
|
+
- [External link](https://github.com/vb64/markdown-pdf)
|
|
83
|
+
- [Internal link to Head1](#head1)
|
|
84
|
+
- [Internal link to Head3](#head3)
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
pdf.add_section(Section(text))
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Add a third section.
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
pdf.add_section(
|
|
95
|
+
Section("# <a name='head1'></a>Head1\n\n\n\nbody\n"),
|
|
96
|
+
user_css="h1 {text-align:center;}"
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
101
|
+
The section has landscape orientation of A4 pages.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Add a section with a table.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
|
|
111
|
+
text = """# Section with Table
|
|
112
|
+
|
|
113
|
+
|TableHeader1|TableHeader2|
|
|
114
|
+
|--|--|
|
|
115
|
+
|Text1|Text2|
|
|
116
|
+
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
120
|
+
|
|
121
|
+
pdf.add_section(Section(text), user_css=css)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Set the properties of the pdf document.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
pdf.meta["title"] = "User Guide"
|
|
128
|
+
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Save to file.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
pdf.save("guide.pdf")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
## Settings and options
|
|
140
|
+
|
|
141
|
+
The `Section` class defines a portion of `markdown` data,
|
|
142
|
+
which is processed according to the same rules.
|
|
143
|
+
The next `Section` data starts on a new page.
|
|
144
|
+
|
|
145
|
+
The `Section` class can set the following attributes.
|
|
146
|
+
|
|
147
|
+
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
148
|
+
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
149
|
+
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
150
|
+
- borders: size of borders. Default (36, 36, -36, -36).
|
|
151
|
+
|
|
152
|
+
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
153
|
+
|
|
154
|
+
- `creationDate`: current date
|
|
155
|
+
- `modDate`: current date
|
|
156
|
+
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
157
|
+
- `producer`: ""
|
|
158
|
+
- `title`: ""
|
|
159
|
+
- `author`: ""
|
|
160
|
+
- `subject`: ""
|
|
161
|
+
- `keywords`: ""
|
|
162
|
+
|
|
163
|
+
## Example
|
|
164
|
+
|
|
165
|
+
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
166
|
+
This [Python script](makepdf.py) was used to create the PDF file.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
git clone git@github.com:vb64/markdown-pdf.git
|
|
172
|
+
cd markdown-pdf
|
|
173
|
+
make setup PYTHON_BIN=/path/to/python3
|
|
174
|
+
make tests
|
|
175
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools>=42",
|
|
4
|
+
"wheel"
|
|
5
|
+
]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "markdown_pdf"
|
|
10
|
+
version = "1.7"
|
|
11
|
+
description = "Markdown to pdf renderer"
|
|
12
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
license = { text = "GNU Affero General Public License v3" }
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Vitaly Bogomolov", email = "mail@vitaly-bogomolov.ru" }
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"License :: OSI Approved :: GNU Affero General Public License v3",
|
|
21
|
+
"Operating System :: OS Independent"
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"PyMuPDF==1.24.6; python_version<'3.9'",
|
|
25
|
+
"PyMuPDF==1.25.3; python_version>'3.8'",
|
|
26
|
+
"markdown-it-py==3.0.0; python_version>='3.8'"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"flake8",
|
|
32
|
+
"pylint",
|
|
33
|
+
"pydocstyle",
|
|
34
|
+
"pytest",
|
|
35
|
+
"pytest-cov",
|
|
36
|
+
"codacy-coverage",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
"Homepage" = "https://github.com/vb64/markdown-pdf"
|
|
41
|
+
"Bug Tracker" = "https://github.com/vb64/markdown-pdf/issues"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
packages = ["markdown_pdf"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.package-data]
|
|
47
|
+
"markdown_pdf" = ["py.typed"]
|
markdown_pdf-1.6/PKG-INFO
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: markdown_pdf
|
|
3
|
-
Version: 1.6
|
|
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
|
-
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
30
|
-
|
|
31
|
-
The module utilizes the functions of two great libraries.
|
|
32
|
-
|
|
33
|
-
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
34
|
-
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
35
|
-
|
|
36
|
-
## Installation
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
pip install markdown-pdf
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Usage
|
|
43
|
-
|
|
44
|
-
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
45
|
-
|
|
46
|
-
```python
|
|
47
|
-
from markdown_pdf import MarkdownPdf
|
|
48
|
-
|
|
49
|
-
pdf = MarkdownPdf(toc_level=2)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Add the first section to the pdf. The title is not included in the table of contents.
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
from markdown_pdf import Section
|
|
56
|
-
|
|
57
|
-
pdf.add_section(Section("# Title\n", toc=False))
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Add a second section with external and internal hyperlinks.
|
|
61
|
-
In the pdf file it starts on a new page.
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
text = """# Section with links
|
|
65
|
-
|
|
66
|
-
- [External link](https://github.com/vb64/markdown-pdf)
|
|
67
|
-
- [Internal link to Head1](#head1)
|
|
68
|
-
- [Internal link to Head3](#head3)
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
pdf.add_section(Section(text))
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Add a third section.
|
|
75
|
-
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.
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
pdf.add_section(
|
|
79
|
-
Section("# <a name='head1'></a>Head1\n\n\n\nbody\n"),
|
|
80
|
-
user_css="h1 {text-align:center;}"
|
|
81
|
-
)
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
85
|
-
The section has landscape orientation of A4 pages.
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Add a section with a table.
|
|
92
|
-
|
|
93
|
-
```python
|
|
94
|
-
|
|
95
|
-
text = """# Section with Table
|
|
96
|
-
|
|
97
|
-
|TableHeader1|TableHeader2|
|
|
98
|
-
|--|--|
|
|
99
|
-
|Text1|Text2|
|
|
100
|
-
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
101
|
-
"""
|
|
102
|
-
|
|
103
|
-
css = "table, th, td {border: 1px solid black;}"
|
|
104
|
-
|
|
105
|
-
pdf.add_section(Section(text), user_css=css)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Set the properties of the pdf document.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
pdf.meta["title"] = "User Guide"
|
|
112
|
-
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Save to file.
|
|
116
|
-
|
|
117
|
-
```python
|
|
118
|
-
pdf.save("guide.pdf")
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-

|
|
122
|
-
|
|
123
|
-
## Settings and options
|
|
124
|
-
|
|
125
|
-
The `Section` class defines a portion of `markdown` data,
|
|
126
|
-
which is processed according to the same rules.
|
|
127
|
-
The next `Section` data starts on a new page.
|
|
128
|
-
|
|
129
|
-
The `Section` class can set the following attributes.
|
|
130
|
-
|
|
131
|
-
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
132
|
-
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
133
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
134
|
-
- borders: size of borders. Default (36, 36, -36, -36).
|
|
135
|
-
|
|
136
|
-
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
137
|
-
|
|
138
|
-
- `creationDate`: current date
|
|
139
|
-
- `modDate`: current date
|
|
140
|
-
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
141
|
-
- `producer`: ""
|
|
142
|
-
- `title`: ""
|
|
143
|
-
- `author`: ""
|
|
144
|
-
- `subject`: ""
|
|
145
|
-
- `keywords`: ""
|
|
146
|
-
|
|
147
|
-
## Example
|
|
148
|
-
|
|
149
|
-
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
150
|
-
This [Python script](makepdf.py) was used to create the PDF file.
|
|
151
|
-
|
|
152
|
-
## Development
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
git clone git@github.com:vb64/markdown-pdf.git
|
|
156
|
-
cd markdown-pdf
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
With Python > 3.8
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
make setup PYTHON_BIN=/path/to/python3
|
|
163
|
-
make tests
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
With Python 3.8
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
170
|
-
make tests
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Platform: UNKNOWN
|
|
174
|
-
Classifier: Programming Language :: Python :: 3
|
|
175
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
176
|
-
Classifier: Operating System :: OS Independent
|
|
177
|
-
Requires-Python: >=3.8
|
|
178
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: markdown-pdf
|
|
3
|
-
Version: 1.6
|
|
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
|
-
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
30
|
-
|
|
31
|
-
The module utilizes the functions of two great libraries.
|
|
32
|
-
|
|
33
|
-
- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
|
|
34
|
-
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
|
|
35
|
-
|
|
36
|
-
## Installation
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
pip install markdown-pdf
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Usage
|
|
43
|
-
|
|
44
|
-
Create a pdf with TOC (bookmarks) from headings up to level 2.
|
|
45
|
-
|
|
46
|
-
```python
|
|
47
|
-
from markdown_pdf import MarkdownPdf
|
|
48
|
-
|
|
49
|
-
pdf = MarkdownPdf(toc_level=2)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Add the first section to the pdf. The title is not included in the table of contents.
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
from markdown_pdf import Section
|
|
56
|
-
|
|
57
|
-
pdf.add_section(Section("# Title\n", toc=False))
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Add a second section with external and internal hyperlinks.
|
|
61
|
-
In the pdf file it starts on a new page.
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
text = """# Section with links
|
|
65
|
-
|
|
66
|
-
- [External link](https://github.com/vb64/markdown-pdf)
|
|
67
|
-
- [Internal link to Head1](#head1)
|
|
68
|
-
- [Internal link to Head3](#head3)
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
pdf.add_section(Section(text))
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Add a third section.
|
|
75
|
-
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.
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
pdf.add_section(
|
|
79
|
-
Section("# <a name='head1'></a>Head1\n\n\n\nbody\n"),
|
|
80
|
-
user_css="h1 {text-align:center;}"
|
|
81
|
-
)
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
|
|
85
|
-
The section has landscape orientation of A4 pages.
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Add a section with a table.
|
|
92
|
-
|
|
93
|
-
```python
|
|
94
|
-
|
|
95
|
-
text = """# Section with Table
|
|
96
|
-
|
|
97
|
-
|TableHeader1|TableHeader2|
|
|
98
|
-
|--|--|
|
|
99
|
-
|Text1|Text2|
|
|
100
|
-
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
101
|
-
"""
|
|
102
|
-
|
|
103
|
-
css = "table, th, td {border: 1px solid black;}"
|
|
104
|
-
|
|
105
|
-
pdf.add_section(Section(text), user_css=css)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Set the properties of the pdf document.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
pdf.meta["title"] = "User Guide"
|
|
112
|
-
pdf.meta["author"] = "Vitaly Bogomolov"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Save to file.
|
|
116
|
-
|
|
117
|
-
```python
|
|
118
|
-
pdf.save("guide.pdf")
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-

|
|
122
|
-
|
|
123
|
-
## Settings and options
|
|
124
|
-
|
|
125
|
-
The `Section` class defines a portion of `markdown` data,
|
|
126
|
-
which is processed according to the same rules.
|
|
127
|
-
The next `Section` data starts on a new page.
|
|
128
|
-
|
|
129
|
-
The `Section` class can set the following attributes.
|
|
130
|
-
|
|
131
|
-
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
132
|
-
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
133
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
134
|
-
- borders: size of borders. Default (36, 36, -36, -36).
|
|
135
|
-
|
|
136
|
-
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
137
|
-
|
|
138
|
-
- `creationDate`: current date
|
|
139
|
-
- `modDate`: current date
|
|
140
|
-
- `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
|
|
141
|
-
- `producer`: ""
|
|
142
|
-
- `title`: ""
|
|
143
|
-
- `author`: ""
|
|
144
|
-
- `subject`: ""
|
|
145
|
-
- `keywords`: ""
|
|
146
|
-
|
|
147
|
-
## Example
|
|
148
|
-
|
|
149
|
-
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
150
|
-
This [Python script](makepdf.py) was used to create the PDF file.
|
|
151
|
-
|
|
152
|
-
## Development
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
git clone git@github.com:vb64/markdown-pdf.git
|
|
156
|
-
cd markdown-pdf
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
With Python > 3.8
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
make setup PYTHON_BIN=/path/to/python3
|
|
163
|
-
make tests
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
With Python 3.8
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
make setup38 PYTHON_BIN=/path/to/python3.8
|
|
170
|
-
make tests
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Platform: UNKNOWN
|
|
174
|
-
Classifier: Programming Language :: Python :: 3
|
|
175
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
176
|
-
Classifier: Operating System :: OS Independent
|
|
177
|
-
Requires-Python: >=3.8
|
|
178
|
-
Description-Content-Type: text/markdown
|
markdown_pdf-1.6/pyproject.toml
DELETED
markdown_pdf-1.6/setup.cfg
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
[metadata]
|
|
2
|
-
name = markdown_pdf
|
|
3
|
-
version = 1.6
|
|
4
|
-
author = Vitaly Bogomolov
|
|
5
|
-
author_email = mail@vitaly-bogomolov.ru
|
|
6
|
-
description = Markdown to pdf renderer
|
|
7
|
-
long_description = file: README.md
|
|
8
|
-
long_description_content_type = text/markdown
|
|
9
|
-
url = https://github.com/vb64/markdown-pdf
|
|
10
|
-
project_urls =
|
|
11
|
-
Bug Tracker = https://github.com/vb64/markdown-pdf/issues
|
|
12
|
-
classifiers =
|
|
13
|
-
Programming Language :: Python :: 3
|
|
14
|
-
License :: OSI Approved :: GNU Affero General Public License v3
|
|
15
|
-
Operating System :: OS Independent
|
|
16
|
-
|
|
17
|
-
[options]
|
|
18
|
-
package_dir =
|
|
19
|
-
packages = markdown_pdf
|
|
20
|
-
python_requires = >=3.8
|
|
21
|
-
install_requires =
|
|
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"
|
|
25
|
-
|
|
26
|
-
[egg_info]
|
|
27
|
-
tag_build =
|
|
28
|
-
tag_date = 0
|
|
29
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|