{"id":27242333,"url":"https://github.com/flayms/markdown2pdf","last_synced_at":"2025-04-10T20:19:20.503Z","repository":{"id":180242620,"uuid":"653785679","full_name":"Flayms/Markdown2Pdf","owner":"Flayms","description":".NET library for converting markdown to PDF.","archived":false,"fork":false,"pushed_at":"2025-03-24T16:36:50.000Z","size":847,"stargazers_count":12,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T02:55:17.457Z","etag":null,"topics":["c-sharp","csharp","dotnet","dotnet-standard","latex","markdown","markdown-to-pdf","mathjax","md2pdf","mermaid","mermaidjs","nuget","nuget-package","pdf","pdf-converter","pdf-generation","vb","vb-net","vbnet","visual-basic-net"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/Markdown2Pdf/","language":"C#","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/Flayms.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-06-14T18:24:52.000Z","updated_at":"2025-04-07T01:40:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"94f5ef19-428f-4bfd-827b-6bc4d68b81fe","html_url":"https://github.com/Flayms/Markdown2Pdf","commit_stats":null,"previous_names":["flayms/markdown2pdf"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flayms%2FMarkdown2Pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flayms%2FMarkdown2Pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flayms%2FMarkdown2Pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flayms%2FMarkdown2Pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flayms","download_url":"https://codeload.github.com/Flayms/Markdown2Pdf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248289590,"owners_count":21078917,"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":["c-sharp","csharp","dotnet","dotnet-standard","latex","markdown","markdown-to-pdf","mathjax","md2pdf","mermaid","mermaidjs","nuget","nuget-package","pdf","pdf-converter","pdf-generation","vb","vb-net","vbnet","visual-basic-net"],"created_at":"2025-04-10T20:19:19.569Z","updated_at":"2025-04-10T20:19:20.488Z","avatar_url":"https://github.com/Flayms.png","language":"C#","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.nuget.org/packages/Markdown2Pdf\" target=\"_blank\" style=\"all: unset;\"\u003e\n    \u003cimg alt=\"Nuget Version\" src=\"https://img.shields.io/nuget/v/Markdown2Pdf\" /\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.nuget.org/packages/Markdown2Pdf\" target=\"_blank\" style=\"all: unset;\"\u003e\n    \u003cimg alt=\"NuGet Downloads\" src=\"https://img.shields.io/nuget/dt/Markdown2Pdf\"\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://github.com/Flayms/Markdown2Pdf/actions/workflows/build-and-release.yml\" target=\"_blank\" style=\"all: unset;\"\u003e\n    \u003cimg src=\"https://github.com/Flayms/Markdown2Pdf/actions/workflows/build-and-release.yml/badge.svg?event=workflow_dispatch\" alt=\"Build and Release\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e Markdown2Pdf\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/md2pdf.svg\" alt=\"Logo\" Width=128px/\u003e\n  \u003cbr\u003e\n\u003c/p\u003e\n\n.NET library for converting Markdown to PDF. Uses [Markdig](https://github.com/xoofx/markdig) for converting markdown to HTML and then [Puppeteer Sharp](https://github.com/hardkoded/puppeteer-sharp) to convert that output to PDF.\n\nFor a cross-platform cli-application using this package checkout [Markdown2Pdf.Console](https://github.com/Flayms/Markdown2Pdf.Console).\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./assets/screenshot.jpg\" alt=\"demo\" Width=450px/\u003e\n\u003c/div\u003e\n\nA full demo PDF can be found [here!](./assets/demo.pdf)\n\n## Usage\n\nC#:\n```cs\nvar converter = new Markdown2PdfConverter();\nvar resultPath = await converter.Convert(\"README.md\");\n```\n\nVB.NET:\n```vb\nDim converter As New Markdown2PdfConverter()\nDim resultPath As String = Await converter.Convert(\"README.md\")\n```\n\n\u003e An enumeration of markdown files can also be passed to the converter, combining them into one PDF.\n\n## Wiki\n\nCheckout the [Wiki](https://github.com/Flayms/Markdown2Pdf/wiki) for more documentation.\n\n## Options\n\nTo further specify the conversion process, pass [Markdown2PdfOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions) to the converter:\n\n```cs\nvar options = new Markdown2PdfOptions {\n  HeaderHtml = \"\u003cdiv class=\\\"document-title\\\" style=\\\"background-color: #5eafed; width: 100%; padding: 5px\\\"\u003e\u003c/div\u003e\",\n  FooterHtml = \"\u003cdiv style=\\\"background-color: #5eafed; width: 100%; padding: 5px\\\"\u003ePage \u003cspan class=\\\"pageNumber\\\"\u003e\u003c/span\u003e/\u003cspan class=\\\"totalPages\\\"\u003e\u003c/span\u003e\u003c/div\u003e\",\n  DocumentTitle = \"Example PDF\",\n};\nvar converter = new Markdown2PdfConverter(options);\n```\n\nAlternatively the [Markdown2PdfOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions) can be loaded from a YAML Front Matter block at the start of the markdown file:\n\n```cs\nvar converter = Markdown2PdfConverter.CreateWithInlineOptionsFromFile(\"README.md\");\nvar resultPath = await converter.Convert(\"README.md\");\n```\n\nUsage examples for this can be found  [here](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Markdown2PdfConverter#-createwithinlineoptionsfromfilestring).\n\n| Option                                                                                                                                           | Description                                                                                                               |\n| ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |\n| [ChromePath](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-chromepath)                                   | Path to chrome or chromium executable or self-downloads it if `null`.                                                     |\n| [CodeHighlightTheme](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-codehighlighttheme)                   | The theme to use for highlighting code blocks.                                                                            |\n| [CustomHeadContent](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-customheadcontent)                     | A `string` containing any content valid inside a HTML `\u003chead\u003e` to apply extra scripting / styling to the document.        |\n| [DocumentTitle](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-documenttitle)                             | The title of this document. Can be injected into the header / footer by adding the class `document-title` to the element. |\n| [EnableAutoLanguageDetection](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-enableautolanguagedetection) | Auto detect the language for code blocks without specfied language.                                                       |\n| [FooterHtml](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-footerhtml)                                   | HTML-string to use as the document footer.                                                                                |\n| [Format](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-format)                                           | The paper format for the PDF.                                                                                             |\n| [HeaderHtml](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-headerhtml)                                   | HTML-string to use as the document header.                                                                                |\n| [IsLandscape](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-islandscape)                                 | Paper orientation.                                                                                                        |\n| [KeepHtml](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-keephtml)                                       | `true` if the created HTML should not be deleted.                                                                         |\n| [MarginOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-marginoptions)                             | Css-margins for the sides of the document.                                                                                |\n| [ModuleOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-moduleoptions)                             | Options that decide from where to load additional modules. [More Information](#modules).                                  |\n| [Scale](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-scale)                                             | Scale of the content. Must be between 0.1 and 2.                                                                          |\n| [TableOfContents](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-tableofcontents)                         | Creates a TOC from the markdown headers. [More Information](#table-of-contents).                                          |\n| [Theme](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-theme)                                             | The styling to apply to the document.                                                                                     |\n\n## Table of contents\n\nTo add a table of contents insert\n* `[TOC]` (Gitlab Syntax)\n* `[[_TOC_]]` (Gitlab Syntax)\n* or `\u003c!-- toc --\u003e` (Comment)\n\ninto the markdown document and use the `Markdown2PdfOptions.TableOfContents` option:\n\n```md\n# My Document\n\n[TOC]\n...\n```\n\nExample creating a TOC:\n\n```cs\noptions.TableOfContents = new TableOfContentsOptions {\n  ListStyle = ListStyle.Decimal,\n\n  // Include all heading levels from 2 to 4.\n  MinDepthLevel = 2,\n  MaxDepthLevel = 4\n};\n```\n\nA header can be omitted from the toc by ending it with `\u003c!-- omit from toc --\u003e`:\n```md\n## This header won't be displayed in the TOC \u003c!-- omit from toc --\u003e\n```\n\nThe TOC gets generated within a `\u003cnav class=\"table-of-contents\"\u003e`. This can be used to apply extra custom styles.\n\n### Options\n\n| Option                                                                                                                          | Description                                               |\n| ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |\n| [HasColoredLinks](hhttps://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.TableOfContentsOptions#-hascoloredlinks)    | If set, the titles in the TOC get default link markup.    |\n| [ListStyle](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.TableOfContentsOptions#-liststyle)                 | Decides which characters to use before the TOC titles.    |\n| [MaxDepthLevel](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.TableOfContentsOptions#-maxdepthlevel)         | The maximum level of heading depth to include in the TOC. |\n| [MinDepthLevel](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.TableOfContentsOptions#-mindepthlevel)         | The minimum level of heading depth to include in the TOC. |\n| [PageNumberOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.TableOfContentsOptions#-pagenumberoptions) | If set, the TOC will be generated with page numbers.      |\n\n## Modules\n\nThis library uses *node_modules* packages.\nBy default they're loaded over the CDN they're hosted on e.g. \u003chttps://cdn.jsdelivr.net\u003e.\n\nYou can also use a local installation by installing the following packages and setting [Markdown2PdfOptions.ModuleOptions](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.Markdown2PdfOptions#-moduleoptions) to [ModuleOptions.FromLocalPath()](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Options.ModuleOptions#-fromlocalpathstring):\n\n```bash\nnpm i mathjax@3\nnpm i mermaid@10\nnpm i font-awesome\nnpm i @highlightjs/cdn-assets@11\nnpm i github-markdown-css\nnpm i latex.css\n```\n\n\u003e **Note:** For this you need to have *npm* installed and added to `PATH`.\n\n| Module                                                                     | Description                               |\n| -------------------------------------------------------------------------- | ----------------------------------------- |\n| [MathJax](https://github.com/mathjax/MathJax)                              | Latex-Math rendering                      |\n| [Mermaid](https://github.com/mermaid-js/mermaid)                           | Diagrams                                  |\n| [Font-Awesome](https://fontawesome.com/)                                   | Icons (Supported within mermaid diagrams) |\n| [Highlight.js](https://github.com/highlightjs/highlight.js)                | Syntax highlighting                       |\n| [github-markdown-css](https://github.com/sindresorhus/github-markdown-css) | Github-Theme                              |\n| [latex-css](https://github.com/vincentdoerig/latex-css)                    | Latex-Theme                               |\n\n### Further modification\n\nTo get more control over the HTML generation (e.g. to add your own JS-Scripts), modify the [converter.ContentTemplate](https://github.com/Flayms/Markdown2Pdf/wiki/Markdown2Pdf.Markdown2PdfConverter#-contenttemplate).\n\n## Unit-Tests\n\nFor automated tests, the project [Markdown2Pdf.Tests](Markdown2Pdf.Tests/) exists.\nBefore starting these, run [setup.ps1](Markdown2Pdf.Tests/setup.ps1).\n\n## Running in Docker\n\nThe bundled Chromium that gets installed by Puppeteer doesn't ship with all necessary dependencies (See [Running Puppeteer in Docker](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker)).\n\nTo resolve this install them in your `.dockerfile`:\n\n```dockerfile\nRUN apt-get update \\\n    \u0026\u0026 apt-get install -y wget gnupg \\\n    \u0026\u0026 wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \\\n    \u0026\u0026 sh -c 'echo \"deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main\" \u003e\u003e /etc/apt/sources.list.d/google.list' \\\n    \u0026\u0026 apt-get update \\\n    \u0026\u0026 apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \\\n      --no-install-recommends \\\n    \u0026\u0026 rm -rf /var/lib/apt/lists/*\n```\n\n## Why is Chromium needed\n\nMarkdown was initially developed so that it can be converted to HTML. Resulting from that, a lot of its tooling exists within the JavaScript world. For instance, [Mermaid](https://github.com/mermaid-js/mermaid) is only implemented in JavaScript, so we need a JS-engine to support it. This results in this package being slower but also able to support more features than other solutions that directly generate the PDF from Markdown.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflayms%2Fmarkdown2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflayms%2Fmarkdown2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflayms%2Fmarkdown2pdf/lists"}