{"id":17543156,"url":"https://github.com/vb64/markdown-pdf","last_synced_at":"2026-02-18T14:05:03.345Z","repository":{"id":197441253,"uuid":"698650333","full_name":"vb64/markdown-pdf","owner":"vb64","description":"Markdown to pdf renderer","archived":false,"fork":false,"pushed_at":"2025-03-19T05:07:34.000Z","size":534,"stargazers_count":75,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T19:04:44.291Z","etag":null,"topics":["markdown","markdown-it","pdf","pymupdf"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vb64.png","metadata":{"files":{"readme":"README.md","changelog":"history.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-30T14:50:58.000Z","updated_at":"2025-03-28T06:03:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"9fccb883-d256-4069-82d5-599bfe92e479","html_url":"https://github.com/vb64/markdown-pdf","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"45369a8a2cf53bbfde90da313a2f0b26d2978e9b"},"previous_names":["vb64/markdown-pdf"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vb64%2Fmarkdown-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vb64%2Fmarkdown-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vb64%2Fmarkdown-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vb64%2Fmarkdown-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vb64","download_url":"https://codeload.github.com/vb64/markdown-pdf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242658,"owners_count":20907131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markdown","markdown-it","pdf","pymupdf"],"created_at":"2024-10-21T00:23:04.410Z","updated_at":"2026-02-18T14:05:03.333Z","avatar_url":"https://github.com/vb64.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Module markdown-pdf\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/pep257.yml?label=Pep257\u0026style=plastic\u0026branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.14\u0026style=plastic\u0026branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_coverage)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)\n\nThe free, open source Python module `markdown-pdf` will create a PDF file from your `markdown` content.\n\nWhen creating a PDF file you can:\n\n- Use `UTF-8` encoded text in `markdown` in any language\n- Embed images used in `markdown`\n- Break text into pages in the desired order\n- Create a TableOfContents (bookmarks) from markdown headings\n- Tune the necessary elements using your CSS code\n- Use different page sizes within single pdf\n- Create tables in `markdown`\n- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.\n- Render plantuml and mermaid code to pdf images with [plugins](plugins.md).\n\nThe module utilizes the functions of two great libraries.\n\n- [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.\n- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.\n\n## Installation\n\n```bash\npip install markdown-pdf\n```\n\n## Usage\n\nCreate a compressed pdf with TOC (bookmarks) from headings up to level 2.\n\n```python\nfrom markdown_pdf import MarkdownPdf\n\npdf = MarkdownPdf(toc_level=2, optimize=True)\n```\n\nAdd the first section to the pdf. The title is not included in the table of contents.\nAfter adding a section to a pdf, the `page_count` property in the section contains the number of pdf pages created for the added section.\n\n```python\nfrom markdown_pdf import Section\n\nsection = Section(\"# Title\\n\", toc=False)\nassert section.page_count == 0\npdf.add_section(section)\nassert section.page_count == 1\n```\n\nAdd a second section with external and internal hyperlinks.\nIn the pdf file it starts on a new page.\n\n```python\ntext = \"\"\"# Section with links\n\n- [External link](https://github.com/vb64/markdown-pdf)\n- [Internal link to Head1](#head1)\n- [Internal link to Head3](#head3)\n\"\"\"\n\npdf.add_section(Section(text))\n```\n\nAdd a third section.\nThe 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.\n\n```python\npdf.add_section(\n  Section(\"# \u003ca name='head1'\u003e\u003c/a\u003eHead1\\n\\n![python](img/python.png)\\n\\nbody\\n\"),\n  user_css=\"h1 {text-align:center;}\"\n)\n```\n\nAdd a next section. Two headings of different levels from this section are included in the TOC of the pdf file.\nThe section has landscape orientation of A4 pages.\n\n```python\npdf.add_section(Section(\"## Head2\\n\\n### \u003ca id='head3'\u003e\u003c/a\u003eHead3\\n\\n\", paper_size=\"A4-L\"))\n```\n\nAdd a section with a table.\n\n```python\n\ntext = \"\"\"# Section with Table\n\n|TableHeader1|TableHeader2|\n|--|--|\n|Text1|Text2|\n|ListCell|\u003cul\u003e\u003cli\u003eFirstBullet\u003c/li\u003e\u003cli\u003eSecondBullet\u003c/li\u003e\u003c/ul\u003e|\n\"\"\"\n\ncss = \"table, th, td {border: 1px solid black;}\"\n\npdf.add_section(Section(text), user_css=css)\n```\n\nThe `sections` property of the `MarkdownPdf` class contains a list of added sections in the order in which they were added.\n\n```python\nassert len(pdf.sections) \u003e 1\n```\n\nSet the properties of the pdf document.\n\n```python\npdf.meta[\"title\"] = \"User Guide\"\npdf.meta[\"author\"] = \"Vitaly Bogomolov\"\n```\n\nSave to file.\n\n```python\npdf.save(\"guide.pdf\")\n```\n\nOr save to file-like object.\n\n```python\nimport io\n\nout = io.BytesIO()\npdf.save_bytes(out)\nassert out.getbuffer().nbytes \u003e 0\n```\n\n![Pdf](img/with_toc.png)\n\n## Settings and options\n\nThe `Section` class defines a portion of `markdown` data,\nwhich is processed according to the same rules.\nThe next `Section` data starts on a new page.\n\nThe `Section` class can set the following attributes.\n\n- toc: whether to include the headers `\u003ch1\u003e` - `\u003ch6\u003e` of this section in the TOC. Default is True.\n- root: the name of the root directory from which the image file paths starts in markdown. Default \".\".\n- 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\".\n- borders: size of borders. Default (36, 36, -36, -36).\n\nThe following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.\n\n- `creationDate`: current date\n- `modDate`: current date\n- `creator`: \"PyMuPDF library: https://pypi.org/project/PyMuPDF\"\n- `producer`: \"\"\n- `title`: \"\"\n- `author`: \"\"\n- `subject`: \"\"\n- `keywords`: \"\"\n\n## Plugins\n\nThe module allows you to process specially marked sections of code using plugins.\n\nFor example, you convert the following Markdown text to PDF:\n\n````markdown\n# Title plantuml\n\nDocument with plantuml code.\n\n```plantuml\n@startuml\nAlice -\u003e Bob: Hello Bob\nBob --\u003e Alice: Hi!\n@enduml\n```\n\nEnd of document\n````\n\nWithout using the plugin, you will get the following result in pdf:\n\n![Without plantuml.jpg](img/without_plantuml.jpg)\n\nYou can use a plugin to render plantuml code into an image.\n\n````python\nfrom markdown_pdf import MarkdownPdf, Section\nfrom markdown_pdf.pligins import Plugin\n\nplantuml_text = \"\"\"# Title plantuml\n\nDocument with plantuml code.\n\n```plantuml\n@startuml\nAlice -\u003e Bob: Hello Bob\nBob --\u003e Alice: Hi!\n@enduml\n```\n\nEnd of document\n\"\"\"\n\nplugins = {\n  Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}\n}\n\npdf = MarkdownPdf(plugins=plugins)\npdf.add_section(Section(plantuml_text))\npdf.save(\"plantuml.pdf\")\n````\n\nIn this case, the plugin will send the code marked as `plantuml` to the specified internet server\nand replace the code text with an image generated by the server `www.plantuml.com`.\n\nIn the created file `plantuml.pdf`, you will see the following result:\n\n![With plantuml.jpg](img/with_plantuml.jpg)\n\nYou can find a more detailed description of the plugins [here](plugins.md).\n\n## Example\n\nAs an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.\nThis [Python script](makepdf.py) was used to create the PDF file.\n\n## Development\n\n```bash\ngit clone git@github.com:vb64/markdown-pdf.git\ncd markdown-pdf\nmake setup PYTHON_BIN=/path/to/python3\nmake tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvb64%2Fmarkdown-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvb64%2Fmarkdown-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvb64%2Fmarkdown-pdf/lists"}