{"id":17081493,"url":"https://github.com/benfoster/migradoc.extensions","last_synced_at":"2025-10-06T12:08:06.691Z","repository":{"id":8398537,"uuid":"9978391","full_name":"benfoster/MigraDoc.Extensions","owner":"benfoster","description":"Extensions for MigraDoc/PDFSharp","archived":false,"fork":false,"pushed_at":"2018-09-24T00:15:49.000Z","size":410,"stargazers_count":28,"open_issues_count":3,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-10T10:13:45.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/benfoster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-10T09:26:56.000Z","updated_at":"2024-07-15T04:50:13.000Z","dependencies_parsed_at":"2022-09-04T00:11:26.057Z","dependency_job_id":null,"html_url":"https://github.com/benfoster/MigraDoc.Extensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfoster%2FMigraDoc.Extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfoster%2FMigraDoc.Extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfoster%2FMigraDoc.Extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfoster%2FMigraDoc.Extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benfoster","download_url":"https://codeload.github.com/benfoster/MigraDoc.Extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631676,"owners_count":21136562,"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":[],"created_at":"2024-10-14T12:53:18.305Z","updated_at":"2025-10-06T12:08:01.661Z","avatar_url":"https://github.com/benfoster.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MigraDoc.Extensions\n\nExtensions for [MigraDoc/PDFSharp](http://www.pdfsharp.net/Overview.ashx).\n\n## Quick Start\n\nThe biggest feature provided by this library is the ability to convert from HTML and Markdown to PDF, via MigraDoc's Document Object Model.\n\nMigraDoc.Extensions makes use of [MarkdownSharp](https://code.google.com/p/markdownsharp/) to convert from Markdown to HTML and the [Html Agility Pack](http://htmlagilitypack.codeplex.com/) to convert from HTML to PDF.\n\nSince the MigraDoc DOM is pretty basic, much of the conversion involves setting the `Style` of generated MigraDoc `Paragraph` instances. You can then configure these styles however you like. See the [example project](https://github.com/benfoster/MigraDoc.Extensions/blob/master/src/examples/MigraDoc.Extensions.Html.Example/Program.cs#L44) for more details.\n\n#### Converting from Markdown to PDF\n\nImport the `MigraDoc.Extensions.Markdown` namespace and call `AddMarkdown` on a MigraDoc `Section` instance:\n\n\n\tvar markdown = @\"\n\t\t# This is a heading\n\n\t\tThis is some **bold** ass text with a [link](http://www.google.com).\n\n\t\t- List Item 1\n\t\t- List Item 2\n\t\t- List Item 3\n\n\t\tPretty cool huh?\n\t\";\n\n\tsection.AddMarkdown(markdown);\n\n\n#### Converting from HTML to PDF\n\nImport the `MigraDoc.Extensions.Html` namespace and call `AddHtml` on a MigraDoc `Section` instance:\n\n\n\tvar html = @\"\n\t\t\u003ch1\u003eThis is a heading\u003c/h1\u003e\n\n\t\t\u003cp\u003eThis is some **bold** ass text with a \u003ca href='http://www.google.com'\u003elink\u003c/a\u003e.\u003cp\u003e\n\n\t\t\u003cul\u003e\n\t\t\t\u003cli\u003eList Item 1\u003c/li\u003e\n\t\t\t\u003cli\u003eList Item 2\u003c/li\u003e\n\t\t\t\u003cli\u003eList Item 3\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\n\t\t\u003cp\u003ePretty cool huh?\u003c/p\u003e\n\t\";\n\n\tsection.AddHtml(html);\n\t\n#### What is supported?\n\nThe HTML converter currently supports the following:\n\n- Headings (H1 -\u003e H6) - Sets a \"HeadingX\" style on the generated paragraph\n- Paragraphs\n- Hyperlinks containing plain text or supported inline elements\n- Lists - Adds a paragraph with style \"ListStart\" before the list and one with style \"ListEnd\" after the list.\n  - Unordered Lists - Each list item has the style \"UnorderedList\"\n  - Ordered Lists - Each list item has the style \"Ordered List\"\n- Line breaks \n- Inline elements `\u003cstrong\u003e`, `\u003cem\u003e`, `\u003ci\u003e`, `\u003cu\u003e`\n- Horizontal Rules - Adds a paragraph with style \"HorizontalRule\"\n\nFor more details, check out the [specs](https://github.com/benfoster/MigraDoc.Extensions/blob/master/src/specs/MigraDoc.Extensions.Html.Specs/converting_tags.cs).\n\n\n#### Extending the HTML converter\n\nTo add a custom handler, create a new instance of `HtmlConverter` and add to its `NodeHandlers` dictionary. The key is the HTML element you wish to handle and the value is a `Func\u003cHtmlNode, DocumentObject, DocumentObject`.\n\nThe `DocumentObject` instance passed to the handler is the parent object in the MigraDoc DOM, usually a `Section` or `Paragraph` (you may need to cater for both). The return value should be the `DocumentObject` that was created. This will be passed as the parent for any child elements. \n\nHere is the handler for processing a `\u003cstrong\u003e` element:\n\n    nodeHandlers.Add(\"strong\", (node, parent) =\u003e {\n        var format = TextFormat.Bold;\n        \n        var formattedText = parent as FormattedText;\n        if (formattedText != null)\n        {\n            return formattedText.Format(format);\n        }\n\n        // otherwise parent is paragraph or section\n        return GetParagraph(parent).AddFormattedText(format);\n    });\n\nIn the above handler, we need to cater for nested format tags (e.g. `\u003cstrong\u003e\u003cem\u003esome text\u003c/em\u003e\u003c/strong\u003e`) so we first attempt to cast the parent as `FormattedText`, otherwise fall back to adding formatted text to a `Paragraph`. Unfortunately such type checks are fairly frequent due to the limited relationships between objects in the MigraDoc DOM.\n\nTo use a custom converter instance use the `Section.Add(string content, IConverter converter)` extension in the `MigraDoc.Extensions` namespace.\n\nNote that an element handler should not process any inner HTML. For example the handler for a `\u003ch1\u003e` tag only adds a paragraph with a the style \"Heading1\", it does not add the text (there is a separate handler for processing text nodes).\n\n\n## License\n\nLicensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenfoster%2Fmigradoc.extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenfoster%2Fmigradoc.extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenfoster%2Fmigradoc.extensions/lists"}