Short answer: PDFsharp does not convert arbitrary HTML to PDF by itself. Its official FAQ says that HTML conversion needs extra code or a third-party renderer. If you can rebuild the content from data, use the PDFsharp-family MigraDoc object model and render that document to PDF. If you must preserve existing HTML and CSS, select and validate a separate HTML rendering engine; do not treat MigraDoc as an HTML parser.
What PDFsharp actually supports
PDFsharp is a PDF-generation library, not a browser engine. The official FAQ question is, “Can I use PDFsharp to convert HTML or RTF to PDF?” Its answer begins “No, not …” and explains that conversion requires additional code or a third-party library. That distinction matters because HTML layout depends on CSS cascading, font metrics, replaced elements, JavaScript, images, and browser-specific behavior. PDFsharp does not provide that browser-style interpretation out of the box.
The FAQ mentions “HTML Renderer for PDF using PdfSharp” as a possible library, but it does not verify that project’s current maintenance, package compatibility, CSS coverage, or licensing. Treat the name as a lead for evaluation, not as a supported PDFsharp feature or a guaranteed solution.
There are therefore two legitimate implementation paths:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches#1 Best Overall
| Path | Starting material | What you build | When it fits |
|---|---|---|---|
| MigraDoc | Structured data, not arbitrary HTML | A document object model rendered to PDF | You control the content model and can recreate the layout |
| Third-party HTML renderer | Existing HTML and CSS | A renderer-specific conversion pipeline | The original markup and browser-like layout must be retained |
Path A: generate a PDF with MigraDoc
MigraDoc is the document-generation library in the PDFsharp family. Its documented workflow is to create a Document, assign it to a PdfDocumentRenderer, call RenderDocument(), and save the renderer’s PDF. This is not HTML conversion: you express paragraphs, tables, sections, styles, and other document elements in the MigraDoc model.
1. Add the PDFsharp/MigraDoc package for your target
Add the PDFsharp/MigraDoc package that matches your application’s target framework and follow that package’s namespace and font requirements. The official technical reference currently reports support for .NET 8, .NET 9, .NET 10, .NET Framework 4.6.2, and .NET Standard 2.0. It lists PDFsharp 6.2.4 dated January 6, 2026, and PDFsharp 7.0.0 Preview 1 dated March 24, 2026. Those are reference-page release and target-framework statements; they do not establish that an HTML renderer supports the same targets.
2. Build the document model
The following C# program demonstrates the documented sequence. Replace the sample text with values from your application rather than trying to pass an HTML string to MigraDoc.
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
var document = new Document();
var section = document.AddSection();
section.PageSetup.TopMargin = Unit.FromCentimeter(2);
section.PageSetup.BottomMargin = Unit.FromCentimeter(2);
var title = section.AddParagraph("Monthly report");
title.Format.Font.Size = 18;
title.Format.Font.Bold = true;
section.AddParagraph("This paragraph is created from structured data.");
var table = section.AddTable();
table.Borders.Width = 0.5;
var header = table.AddRow();
header.Cells[0].AddParagraph("Item");
header.Cells[1].AddParagraph("Value");
var row = table.AddRow();
row.Cells[0].AddParagraph("Completed");
row.Cells[1].AddParagraph("42");
var renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save("report.pdf");
The important calls are renderer.Document = document, renderer.RenderDocument(), and renderer.PdfDocument.Save(...). A successful run creates report.pdf in the process’s current working directory. In a web application, supply an explicit writable path or stream and return the resulting bytes through your framework instead of assuming the server’s working directory is stable.
3. Recreate only the HTML features you need
Translate your source data into MigraDoc paragraphs, sections, tables, images, and styles. Establish named styles for body text, headings, captions, and table cells so that a later design change does not require editing every paragraph. Add explicit page breaks where a report section must start on a new page, and keep long tables in a repeatable structure that you can verify in generated PDFs.
Do not describe this route as importing HTML. MigraDoc’s documented pages describe a document-object-model workflow, not an HTML parser, CSS cascade, JavaScript runtime, or browser layout engine.
Fonts are part of a production MigraDoc build
Font resolution affects line wrapping, pagination, glyph availability, and therefore the final PDF. The official settings guidance recommends a custom font resolver for production and especially for .NET Core builds outside Windows. Configure a resolver that can locate every font family your styles use, and deploy the font files with the application when the runtime machine does not provide them.
Check these font failure symptoms
- Text is replaced by a fallback typeface or boxes because a glyph is unavailable.
- Lines wrap differently between a developer workstation and a Linux or container deployment.
- A document renders locally but fails in a headless service because the requested font cannot be resolved.
- Page breaks move after deployment because fallback metrics are wider or narrower.
Test with non-ASCII characters, including the languages your users actually enter. Keep licensing records for any font files you redistribute; the PDFsharp documentation does not grant rights to third-party fonts.
Path B: convert existing HTML with a separate renderer
Choose this path when the HTML already exists and preserving its layout is more important than using PDFsharp alone. The renderer, not PDFsharp, will interpret the markup and CSS. Before committing, request a small proof-of-concept using representative pages: nested tables, web fonts, images, long text, right-to-left text if applicable, print media rules, page headers, and deliberate page breaks.
Questions to answer before adoption
- Maintenance: Is the renderer actively maintained, and are releases and issue responses visible?
- Target frameworks: Does its current package support your exact .NET runtime, operating system, CPU architecture, and deployment model?
- HTML/CSS coverage: Which layout systems, selectors, fonts, SVG features, forms, and print rules are implemented?
- External resources: How are HTTPS certificates, redirects, authentication, cookies, local files, and blocked network requests handled?
- Licensing: Can you use and redistribute it in your product and deployment topology?
- Security: Can untrusted HTML trigger network access, local-file reads, excessive memory use, or script execution?
The PDFsharp FAQ’s mention of HTML Renderer for PDF using PdfSharp does not answer these questions. Verify them against the renderer’s current documentation and package metadata, then pin and test the exact version you deploy.
Keep the boundary clear in your code
A maintainable service usually has an HTML-rendering component that produces a PDF stream, or a data-to-MigraDoc component that produces a PDF stream. Avoid a misleading API named ConvertHtmlWithPdfsharp if it actually invokes another engine; name the dependency and record its version so a future upgrade can be tested independently.
Validation and production testing
PDF creation succeeding is not the same as the document being correct. Compare generated files against acceptance cases and inspect the rendered pages, not just the PDF byte stream.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use a representative test set
- Short and very long paragraphs that force line wrapping.
- Tables with enough rows to cross several pages.
- Images at their intrinsic size, a constrained size, and a missing or slow URL.
- Unicode characters and any required right-to-left or complex-script content.
- Headings at page bottoms, explicit page breaks, and empty sections.
- Production fonts and the same operating system or container image used in deployment.
Check deterministic output where it matters
Some PDF metadata, object identifiers, or timestamps can differ between runs even when the visible pages are identical. For regression testing, compare extracted text, page count, dimensions, and rasterized page images rather than requiring byte-for-byte identity unless your pipeline deliberately normalizes metadata.
Troubleshooting common failures
“PDFsharp does not accept my HTML string”
Cause: There is no built-in HTML parser or conversion method. Fix: either map your data into MigraDoc or integrate a separately maintained HTML renderer and follow its API.
The PDF is blank or has missing sections
Cause: The document model may contain no elements, a section may be empty, or an external renderer may have failed to load a resource. Fix: log the input and element count, save a minimal document, and test images, styles, and remote resources separately. For HTML engines, capture renderer diagnostics and use local, known-good assets during isolation.
Fonts work on Windows but not in a container
Cause: The deployment image lacks the requested fonts or a resolver cannot locate them. Fix: configure the custom resolver recommended by the MigraDoc settings guidance, deploy permitted font files, and test the actual production image.
Pagination changes after deployment
Cause: Different fonts, renderer versions, culture settings, or image dimensions alter layout metrics. Fix: pin versions, set culture and page settings explicitly, use the same font files, and add visual regression cases around page boundaries.
HTML styling is substantially different in the PDF
Cause: The selected renderer does not implement a CSS feature, print rule, web font, or JavaScript behavior used by the page. Fix: identify the unsupported feature in a reduced test page, simplify the markup, or choose a renderer whose documented coverage matches the requirement. Do not assume that a library named “HTML Renderer” has full browser parity.
Output is slow or memory-heavy
Cause: Very large images, huge tables, repeated font loading, or multiple conversions running concurrently. Fix: resize images before embedding, process large jobs in bounded batches, reuse immutable configuration, set request and job timeouts for external resources, and measure peak memory with production-sized inputs. Keep a queue or concurrency limit so one unusually large document cannot exhaust the service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and cost decisions
MigraDoc is usually the more predictable option when you control the data model: there is no browser startup, and the generated layout is limited to features you explicitly create. The trade-off is engineering time to recreate an existing HTML design. An HTML renderer can preserve more of the original markup, but its compatibility, resource loading, and maintenance become additional operational dependencies.
Free tools Windows power users keep installed
One-click scans. No signup required.
Budget for more than a library license. Account for font licenses, renderer support, container images, test fixtures, monitoring, and the cost of investigating layout regressions after upgrades. The cited PDFsharp material establishes the direct-conversion limitation and MigraDoc sequence, but it does not establish comparative fidelity, throughput, or compatibility for any particular third-party HTML renderer. Measure those properties with your pages before making a capacity or product commitment.
Rank #4
Or skip the browser setup
If your HTML is already available at a URL and you want a rendered capture rather than rebuilding the document model, ScreenshotNeo is an alternative to try first: it removes cookie banners, newsletter popups, and chat widgets before capture, bills only clean shots, and reports the page verdict and billing status in response headers. Its API can return PNG, JPEG, WebP, or PDF, and its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
For a one-call capture, see the parameter details in the ScreenshotNeo documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request from Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
And Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Replace the example URL with the deployed page you are allowed to capture and select the required output in the API options. ScreenshotNeo does not charge for bot checks or CAPTCHAs, blank pages, timeouts, failed loads, or cache hits. It also supports full-page captures with lazy images loaded, CSS-selector element capture, custom CSS and JavaScript, click actions, selector or network-idle waits, ad and tracker blocking, custom headers and cookies, authentication, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify a migration.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
| Plan | Monthly price | Included shots |
|---|---|---|
| Free | $0 | 1,000 |
| Starter | $5 | 3,000 |
| Growth | $15 | 15,000 |
| Pro | $39 | 60,000 |
| Scale | $99 | 250,000 |
| Business | $249 | 1,000,000 |
These are the listed monthly plans; yearly billing gives two months free, and every feature is available on every plan. You can start with 1,000 free screenshots a month with no card; paid plans start at $5 for 3,000 shots.
FAQ
Can MigraDoc import an existing HTML page?
No documented MigraDoc workflow provides an HTML or CSS parser. It renders the document model you construct.
Is PDFsharp 7.0.0 ready for every production use?
The technical reference labels 7.0.0 as Preview 1 dated March 24, 2026. Decide based on your own risk policy and test the exact build; the reference also lists 6.2.4 dated January 6, 2026.
Will an HTML renderer that mentions PdfSharp support .NET 10?
Not necessarily. PDFsharp’s reported target support does not prove compatibility for a separate renderer. Confirm that renderer’s package targets and run a proof-of-concept on your deployment runtime.
Recommended Free Tools
What should I do when the source is RTF instead of HTML?
PDFsharp’s FAQ groups RTF with HTML as formats it does not convert directly. Use a dedicated RTF conversion path or rebuild the content in MigraDoc.
Frequently Asked Questions
Can MigraDoc import an existing HTML page?
No. Its documented workflow renders a document model that you construct; it is not an HTML/CSS parser.
Will an HTML renderer that mentions PdfSharp support .NET 10?
Not automatically. Verify the separate renderer’s package targets and test it on your deployment runtime.
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.




