Skip to main content

Markdown to pdf renderer

Project description

markdown-pdf

GitHub Workflow Status GitHub Workflow Status Codacy Badge Codacy Badge

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")

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

markdown_pdf-1.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

markdown_pdf-1.1-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page