You can convert controlled HTML to PDF with MigraDoc by using a third-party HTML extension, such as MigraDoc.Extensions, to add the markup to a MigraDoc section, then rendering the document with PdfDocumentRenderer. MigraDoc does not import arbitrary HTML by itself: this route is for supported structural elements, not for reproducing a modern web page with browser-level CSS and JavaScript.
What MigraDoc does—and what it does not do
MigraDoc is a .NET document generator built around a document object model. You assemble content such as paragraphs, tables, sections, styles, images, headers, and footers; MigraDoc lays out that document and PDFsharp renders it to PDF. That makes it a natural fit for reports, invoices, letters, and other structured documents whose layout you control.
It is not a web browser. The PDFsharp FAQ says HTML-to-PDF conversion is not included out of the box. To import HTML, you must add your own conversion code or use a third-party library. MigraDoc.Extensions provides one such route: its HTML extension parses markup with Html Agility Pack and maps supported elements into MigraDoc objects.
The distinction matters: converting a heading and list from controlled markup is different from printing a live site. Do not assume this approach executes JavaScript, applies arbitrary CSS, follows responsive breakpoints, or produces a pixel-perfect copy of a page.
#1 Best Overall
What HTML MigraDoc.Extensions documents
The extension documents support for these structural elements:
<h1>through<h6>, mapped to the correspondingHeadingXparagraph styles.- Paragraphs.
- Hyperlinks containing plain text or supported inline elements.
- Unordered lists and ordered lists, with list-item styling.
That is a useful base for simple documents, but it is not a complete HTML/CSS specification. Before relying on additional tags, inline formatting, images, tables, or styles, check the extension’s current documentation and test the exact markup you intend to convert. Its Markdown support is a separate AddMarkdown extension that converts Markdown to HTML using MarkdownSharp before the HTML conversion step.
Prepare the .NET project and dependencies
The official MigraDoc reference lists support for .NET 8, .NET 9, .NET 10, .NET Framework 4.6.2, and .NET Standard 2.0. That describes MigraDoc; it does not establish that every version of MigraDoc.Extensions and its parser supports every one of those targets. Check the current package metadata and project documentation for the target framework and package versions you plan to use before adding them to a production project.
Add compatible references to MigraDoc, its PDFsharp rendering dependency, and MigraDoc.Extensions using the package manager and versions selected for your application. The project and extension versions are not specified here, so there is no safe universal package command or version number to copy. Confirm that the references resolve together for your target framework before proceeding.
Rank #2
Convert a controlled HTML string to PDF
The example below demonstrates the documented extension method and MigraDoc renderer sequence. It uses a heading, paragraphs, a link, and both list types from the documented subset. It assumes the compatible packages and required namespace references are already in the project.
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.Extensions.Html;
var html = """
<h1>Quarterly Summary</h1>
<p>Revenue increased during the quarter.</p>
<p>See the <a href="https://example.com/report">supporting report</a>.</p>
<h2>Highlights</h2>
<ul>
<li>Customer renewals increased</li>
<li>Operating costs remained stable</li>
</ul>
<h2>Next steps</h2>
<ol>
<li>Review regional results</li>
<li>Set next quarter targets</li>
</ol>
""";
var document = new Document();
var section = document.AddSection();
section.AddHtml(html);
var renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.Save("output.pdf");
- Supply the markup. Put the HTML string, or content read from your application, in
html. Treat it as input for a document converter, not as a full web page. - Create the MigraDoc document and section.
section.AddHtml(html)is the extension call that parses supported markup and adds its mapped content to the document model. - Render and save. Assign the document to
PdfDocumentRenderer, callRenderDocument(), then save the resulting PDF. Pagination and final object positions are determined during rendering.
For a project that does not support C# raw string literals, replace the triple-quoted string with a normal escaped string or load the HTML from a file. The conversion and rendering calls remain the same.
Control document layout and extend the output
HTML import supplies content; it does not remove the need to design the document. MigraDoc is responsible for document layout, including page breaks. Set up the page and document structure that your output needs, and check the resulting PDF for heading hierarchy, list spacing, page breaks, and link behavior. The extension maps headings to MigraDoc’s HeadingX styles, so document styles are the place to investigate when you need to control the appearance of those headings.
For production documents, make a representative input set and inspect the rendered files whenever you change markup, styles, fonts, or package versions. The conversion path is a mapping into MigraDoc’s model; unsupported or differently interpreted markup may not match how a browser displays it. Do not depend on a web font, CSS rule, or image-rendering behavior until you have verified that the extension and your document setup support it.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →If you need page-level additions such as a watermark, custom drawing, or background, render the MigraDoc document first and then use PDFsharp with the resulting PdfDocument. This separates document flow and pagination from PDF-level drawing or processing.
Know when this approach is the wrong fit
- Choose MigraDoc with an HTML extension when your input is controlled, mostly structural HTML and you want a code-defined document model with MigraDoc layout and pagination.
- Choose a browser-based renderer when the source is a live website or fidelity depends on browser CSS, responsive layout, or JavaScript execution. That is a different rendering approach, not a capability to assume from
AddHtml. - Use PDFsharp after rendering when the document is already laid out but needs PDF-level drawing or modification.
There is no performance benchmark or conversion-success rate established for this extension here. Test with your own inputs, especially if your workload has large documents, complex markup, or strict fidelity requirements, and check the extension’s maintenance and compatibility status before making it a production dependency.
Troubleshooting common problems
The extension method AddHtml is not found
Confirm that the project references the intended MigraDoc.Extensions package and that using MigraDoc.Extensions.Html; is present. Also verify that the package version you selected exposes the documented extension API and is compatible with your target framework.
The PDF is missing or changes parts of the HTML
Start with the documented subset—headings, paragraphs, links, and lists—and reduce the input to the smallest failing example. Check whether the element or formatting you rely on is documented by the extension. Browser behavior is not evidence that a tag or CSS rule will be represented in MigraDoc.
Recommended Free Tools
Rank #4
- Funny saying for any front-end developer, web developer, computer programmer, computer systems engineer, mobile app developer, software developer, or code lover who likes to code, make funny programming jokes, and take memorable photos.
- Wear it proudly at International Programmers' Day, school, coding classes, or coding communities! It also makes a funny present for a computer programming lover friend.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
The project fails to restore or build
Check the target framework and the compatibility of the MigraDoc, PDFsharp, extension, and parser package versions together. The core reference’s supported targets do not guarantee compatibility for a separate third-party extension. Use package versions that the extension itself supports, then restore and build before integrating conversion code.
Page breaks or spacing differ from expectations
Remember that layout is finalized during RenderDocument(). Inspect the rendered PDF rather than judging only the input HTML, and adjust the MigraDoc document structure or supported styles. If the requirement is to reproduce a page as a browser lays it out, switch to a browser rendering engine instead of trying to tune a structural importer into one.
Or skip the browser setup
If your source is a live webpage and you want an image capture rather than a MigraDoc-generated document, ScreenshotNeo is a screenshot API and MCP server from Yorker Media. This is an alternative for webpage capture, not a replacement for importing arbitrary HTML into MigraDoc. Its one-request API can capture a URL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for API parameters and PDF output options. ScreenshotNeo accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Free tools Windows power users keep installed
One-click scans. No signup required.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
Best Value
- Programming Language Lover Code Apparel. App or Web Design and Development Expert Funny Dress. Best Valentines Idea For Coding Lover. HTML Code or Meaning Costume
- Funny I Know HTML - How To Meet Ladies Computer Programmer Quotes
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Make the choice based on the source
For controlled HTML that needs to become a structured report or letter, parse only the markup you need with a compatible extension, then let MigraDoc paginate and PDFsharp render the document. For a web page whose appearance depends on browser behavior, use a browser-based renderer and treat that as a separate route. Keeping those jobs distinct avoids expecting MigraDoc’s document model to behave like a browser.
Frequently Asked Questions
Can MigraDoc convert Markdown to PDF through this extension?
MigraDoc.Extensions documents a separate AddMarkdown extension that converts Markdown to HTML with MarkdownSharp before using the HTML conversion route.
Can I add a watermark after creating the PDF?
Yes. Render the MigraDoc document first, then use PDFsharp with the resulting PdfDocument for page-level drawing or modifications.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

