Markdown to pdf renderer
Project description
markdown-pdf
This is a small Python class that links two libraries:
markdown-it-py and
PyMuPDF.
This class will create a PDF file from your set of markdown
files.
Installation
pip install markdown-pdf
Usage
Create a pdf with TOC (bookmarks) from headings up to level 2.
from markdown_pdf import MarkdownPdf
pdf = MarkdownPdf(toc_level=2)
Add three sections of markdown to the pdf. Each section starts on a new page. Headings from the first section are not included in the TOC. The second section header is centered using CSS.
from markdown_pdf import Section
pdf.add_section(Section("# Title\n", toc=False))
pdf.add_section(Section("# Head1\n\nbody\n"), user_css="h1 {text-align:center;}")
pdf.add_section(Section("## Head2\n\n### Head3\n\n"))
Set the properties of the pdf document.
pdf.meta["title"] = "User Guide"
pdf.meta["author"] = "Vitaly Bogomolov"
Save to file.
pdf.save("guide.pdf")
The Section
class defines a portion of markdown
data,
which is processed according to the same rules.
The next Section
data starts on a new page.
The Section
class can set the following attributes.
- toc: whether to include the headers
<h1>
-<h6>
of this section in the TOC. Default is True. - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
- paper_size: name of paper size, as described here. Default "A4".
- borders: size of borders. Default (36, 36, -36, -36).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for markdown_pdf-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de23f6b529b2ebe7bab5625a6f294e437b2998f1ab2d70383e828be19c0d9ec0 |
|
MD5 | 9ff4f37bf17ce2df0fafadf2ed31ede3 |
|
BLAKE2b-256 | 6352b8a45e64fbad7a8196fbb1817f2126d819b7f8ecb29fbb7d2f37e29e5678 |