markdown-pdf 1.8__tar.gz → 1.10__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown_pdf
3
- Version: 1.8
3
+ Version: 1.10
4
4
  Summary: Markdown to pdf renderer
5
5
  Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
6
  License: GNU Affero General Public License v3
@@ -13,7 +13,7 @@ Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
16
- Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
16
+ Requires-Dist: PyMuPDF>=1.25.3; python_version > "3.8"
17
17
  Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
18
18
  Provides-Extra: dev
19
19
  Requires-Dist: flake8; extra == "dev"
@@ -156,7 +156,7 @@ The `Section` class can set the following attributes.
156
156
 
157
157
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
158
158
  - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
159
- - paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
159
+ - paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
160
160
  - borders: size of borders. Default (36, 36, -36, -36).
161
161
 
162
162
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -131,7 +131,7 @@ The `Section` class can set the following attributes.
131
131
 
132
132
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
133
133
  - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
134
- - paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
134
+ - paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
135
135
  - borders: size of borders. Default (36, 36, -36, -36).
136
136
 
137
137
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -6,9 +6,11 @@ import pathlib
6
6
  import fitz
7
7
  from markdown_it import MarkdownIt
8
8
  from pymupdf import (
9
- _as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF,
9
+ _as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF, Rect,
10
10
  )
11
11
 
12
+ MM_2_PT = 2.835
13
+
12
14
 
13
15
  class Section:
14
16
  """Markdown section."""
@@ -18,15 +20,25 @@ class Section:
18
20
  text: str,
19
21
  toc: bool = True,
20
22
  root: str = ".",
21
- paper_size: str = "A4",
23
+ paper_size: str or list or tuple = "A4",
22
24
  borders: typing.Tuple[int, int, int, int] = (36, 36, -36, -36)
23
25
  ):
24
26
  """Create md section with given properties."""
25
27
  self.text = text
26
28
  self.toc = toc
27
29
  self.root = root
28
- # https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size
30
+
29
31
  self.paper_size = paper_size
32
+ if isinstance(paper_size, str):
33
+ # https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size
34
+ self.rect = fitz.paper_rect(paper_size)
35
+ elif isinstance(paper_size, (list, tuple)):
36
+ # Other paper sizes are in pt, so need to times mm by 2.835.
37
+ width, height = paper_size
38
+ self.rect = Rect(0.0, 0.0, (width * MM_2_PT), (height * MM_2_PT))
39
+ else:
40
+ raise TypeError("paper_size must be 'str', 'tuple' or 'list'")
41
+
30
42
  self.borders = borders
31
43
 
32
44
 
@@ -81,14 +93,13 @@ class MarkdownPdf:
81
93
 
82
94
  def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> str:
83
95
  """Add markdown section to pdf."""
84
- rect = fitz.paper_rect(section.paper_size)
85
- where = rect + section.borders
96
+ where = section.rect + section.borders
86
97
  html = self.m_d.render(section.text)
87
98
  story = fitz.Story(html=html, archive=section.root, user_css=user_css)
88
99
  more = 1
89
100
  while more: # loop outputting the story
90
101
  self.page_num += 1
91
- device = self.writer.begin_page(rect)
102
+ device = self.writer.begin_page(section.rect)
92
103
  more, _ = story.place(where) # layout into allowed rectangle
93
104
  story.element_positions(self._recorder, {"toc": section.toc, "pdfile": self})
94
105
  story.draw(device)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown_pdf
3
- Version: 1.8
3
+ Version: 1.10
4
4
  Summary: Markdown to pdf renderer
5
5
  Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
6
  License: GNU Affero General Public License v3
@@ -13,7 +13,7 @@ Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
  Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
16
- Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
16
+ Requires-Dist: PyMuPDF>=1.25.3; python_version > "3.8"
17
17
  Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
18
18
  Provides-Extra: dev
19
19
  Requires-Dist: flake8; extra == "dev"
@@ -156,7 +156,7 @@ The `Section` class can set the following attributes.
156
156
 
157
157
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
158
158
  - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
159
- - paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
159
+ - paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
160
160
  - borders: size of borders. Default (36, 36, -36, -36).
161
161
 
162
162
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -3,7 +3,7 @@
3
3
  PyMuPDF==1.24.6
4
4
 
5
5
  [:python_version > "3.8"]
6
- PyMuPDF==1.25.3
6
+ PyMuPDF>=1.25.3
7
7
 
8
8
  [:python_version >= "3.8"]
9
9
  markdown-it-py==3.0.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "markdown_pdf"
10
- version = "1.8"
10
+ version = "1.10"
11
11
  description = "Markdown to pdf renderer"
12
12
  readme = { file = "README.md", content-type = "text/markdown" }
13
13
  requires-python = ">=3.8"
@@ -22,7 +22,7 @@ classifiers = [
22
22
  ]
23
23
  dependencies = [
24
24
  "PyMuPDF==1.24.6; python_version<'3.9'",
25
- "PyMuPDF==1.25.3; python_version>'3.8'",
25
+ "PyMuPDF>=1.25.3; python_version>'3.8'",
26
26
  "markdown-it-py==3.0.0; python_version>='3.8'"
27
27
  ]
28
28
 
File without changes
File without changes
File without changes