{"id":6713,"library":"markdown-pdf","title":"Markdown-pdf","description":"markdown-pdf is a Python library designed to convert Markdown documents into PDF files. It utilizes `markdown-it-py` for efficient Markdown to HTML conversion and `PyMuPDF` for robust HTML to PDF rendering. Currently at version 1.13.1, the library is actively maintained with several releases per year, continuously adding new features and improvements.","status":"active","version":"1.13.1","language":"en","source_language":"en","source_url":"https://github.com/vb64/markdown-pdf","tags":["markdown","pdf","conversion","document","pymupdf","agpl"],"install":[{"cmd":"pip install markdown-pdf","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for converting Markdown syntax to HTML.","package":"markdown-it-py"},{"reason":"Used for rendering HTML content into PDF format.","package":"PyMuPDF"},{"reason":"A dependency explicitly fixed in a recent release, likely for handling external resources.","package":"requests"}],"imports":[{"symbol":"MarkdownPdf","correct":"from markdown_pdf import MarkdownPdf"},{"symbol":"Section","correct":"from markdown_pdf import Section"}],"quickstart":{"code":"from markdown_pdf import MarkdownPdf, Section\nimport os\n\n# Create a PDF with a Table of Contents (up to level 2 headings) and optimized output\npdf = MarkdownPdf(toc_level=2, optimize=True)\n\n# Add the first section. The 'toc=False' ensures its title is not in the TOC.\npdf.add_section(Section(\"# Document Overview\\n\\nThis is an introduction to the document.\", toc=False))\n\n# Add a second section with external and internal hyperlinks\ntext_with_links = \"\"\"\n# Hyperlink Section\n\n- [External Link to GitHub](https://github.com/vb64/markdown-pdf)\n- [Internal Link to Subsection](#introduction-to-python)\n\n## Introduction to Python\nPython is a versatile programming language.\n\"\"\"\npdf.add_section(Section(text_with_links))\n\n# Add a third section with custom CSS applied to its headings\ntext_with_css = \"\"\"\n# Custom Styled Header\n\nThis section demonstrates custom CSS to center its main heading.\n\"\"\"\npdf.add_section(Section(text_with_css, user_css=\"h1 {text-align:center; font-size: 2em;}\"))\n\n# Set PDF document metadata\npdf.meta[\"title\"] = \"Markdown-pdf Example Guide\"\npdf.meta[\"author\"] = \"AI Assistant\"\n\n# Define the output file name\noutput_filename = os.environ.get('PDF_OUTPUT_FILE', 'example_document.pdf')\n\n# Save the generated PDF to a file\npdf.save(output_filename)\nprint(f\"PDF '{output_filename}' generated successfully.\")","lang":"python","description":"This quickstart demonstrates how to create a multi-section PDF from Markdown strings. It shows initializing `MarkdownPdf` with options like `toc_level` and `optimize`, adding individual `Section` objects with custom settings (like disabling TOC for a section or applying `user_css`), and finally setting document metadata before saving the PDF to a file."},"warnings":[{"fix":"Assess the impact of the AGPL-3.0 license on your project's usage, distribution, and overall licensing strategy.","message":"The project's license changed from MIT to AGPL-3.0 starting with version 1.6. Users of versions 1.6 and newer must review and comply with the AGPL-3.0 license terms.","severity":"breaking","affected_versions":">=1.6"},{"fix":"Familiarize yourself with the AGPL-3.0 license to understand its implications for your software's distribution and source code availability.","message":"The core PDF generation relies on `PyMuPDF`, which is licensed under AGPL-3.0. This underlying dependency means that projects linking with or distributing `markdown-pdf` are generally subject to the copyleft provisions of the AGPL-3.0 license.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly set the `root` parameter in `Section(markdown_content, root='path/to/image_assets')` to the base directory containing your image files.","message":"When embedding images, relative paths are resolved using the `root` parameter of the `Section` class (defaults to current working directory). Incorrect `root` settings can cause images to be missing in the output PDF.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To have content flow continuously on a single page, combine all desired Markdown content into a single `Section` object.","message":"By default, each `Section` added to a `MarkdownPdf` instance will start on a new page. This is the intended behavior for logical document structuring but can be a 'gotcha' if you expect continuous flow.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the `markdown-pdf` documentation to understand how to enable and configure these plugins for diagram rendering.","message":"Rendering PlantUML and Mermaid diagrams requires enabling specific plugins (`plantuml_plugin`, `mermaid_plugin`) when initializing `MarkdownPdf`; they are not active by default.","severity":"gotcha","affected_versions":"PlantUML: >=1.11, Mermaid: >=1.12"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}