Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

For a PDF that looks like a browser-printed web page, render the HTML with a browser engine from .NET. Microsoft Playwright for .NET is a practical starting point: load an HTML string, file, or URL in Chromium and call Page.PdfAsync. It uses print CSS by default; install Playwright’s browser binaries as well as the NuGet package before running it.

Choose a rendering approach

HTML-to-PDF is a rendering task, not simply a file-format conversion. The renderer must interpret HTML, CSS, fonts, images, and any page scripts, then paginate the result. The best choice depends on whether you need browser-like output or a PDF layout defined directly in C#.

Approach Rendering model Useful when Operational points
Microsoft Playwright for .NET Browser-based HTML and CSS rendering in Chromium You want browser automation APIs and control over page media and PDF options Install the NuGet package and the browser binaries required by the deployment environment. Playwright setup
PuppeteerSharp Browser-based rendering through headless Chromium Your application already uses PuppeteerSharp or its API suits your workflow Its API documentation shows launching Chromium, navigating to a page, and calling PdfAsync. Confirm browser and runtime setup for your target OS. PuppeteerSharp API documentation
IronPDF HTML rendering behind a .NET library API with an embedded Chromium engine You prefer an integrated commercial library The quickstart includes license-key setup. Verify current licensing, platform support, and deployment requirements for your exact version. A base URL can help resolve relative assets. IronPDF quickstart ChromePdfRenderer API
QuestPDF Code-first PDF layout APIs rather than HTML conversion You can define and maintain the document’s structure in C# Review the current license categories and eligibility before production use. The cited examples demonstrate PDF composition and ASP.NET output, not HTML rendering. QuestPDF quick start QuestPDF license

The examples below use Playwright. They illustrate the documented API shape; check the current package API and browser-install instructions for your version and deployment platform. No single approach is established here as a performance winner.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up Playwright for .NET

Add the package to your project, then install the browser binaries. Playwright’s setup documentation covers the browser installation step and platform-specific requirements.

#1 Best Overall
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
  1. From your project directory, add the NuGet package:

    dotnet add package Microsoft.Playwright

  2. Build the project so the Playwright installation script is available:

    dotnet build

  3. Install the required browser binaries using the Playwright install script generated in the build output. Follow the current .NET installation documentation for the command and any operating-system dependencies.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Run the application in an environment where the installed browser can launch. A package reference alone does not supply every browser runtime needed for PDF generation.

Render an HTML string to PDF

This minimal asynchronous example sets HTML content and writes a PDF to disk. The API returns a PDF buffer; supplying Path saves it to that path.

using Microsoft.Playwright;

var html = "<!doctype html><html><head><meta charset='utf-8'><title>Report</title></head><body><h1>Hello from C#</h1><p>This page will be rendered as a PDF.</p></body></html>";

Rank #2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.SetContentAsync(html);
await page.PdfAsync(new() { Path = "output.pdf" });

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For ASP.NET or another service, consider returning the PDF bytes rather than writing to a shared fixed filename. The documentation’s core operation is PdfAsync, which returns the page PDF buffer; the path option is convenient for a local example or file workflow. Playwright Page.PdfAsync API

Render a local HTML file or a URL

Open a local file

Navigate to a file URI, then generate the PDF. Use an absolute path so the process’s working directory does not change which file is opened.

using Microsoft.Playwright;

var filePath = Path.GetFullPath("report.html");
var fileUrl = new Uri(filePath).AbsoluteUri;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync(fileUrl);
await page.PdfAsync(new() { Path = "report.pdf" });

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Relative CSS, images, or script paths need to resolve from the file’s location or be provided with usable absolute URLs. Verify that local files are available to the process account and deployment container.

Rank #3
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
  • Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
  • Edit text and images without jumping to another app.
  • E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
  • Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
  • Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.

Open a web page

Use GotoAsync for a URL before printing. Choose a wait condition that matches the page: the browser’s navigation completion does not necessarily mean every application-specific render or late-loading asset is ready.

var response = await page.GotoAsync("https://example.com");
if (response is null || !response.Ok)
{
  throw new InvalidOperationException($"Navigation failed: {response?.Status}");
}

await page.PdfAsync(new() { Path = "page.pdf" });

For pages that render asynchronously, wait for a meaningful selector before printing, for example await page.Locator("#report-ready").WaitForAsync();. Use a selector that the page actually exposes; arbitrary fixed delays can make the job slower without ensuring that fonts, images, or data are ready.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control print CSS, paper size, and margins

Print media versus screen media

PdfAsync uses print CSS media by default. This is usually appropriate for documents with @media print rules. If the page is designed for screen CSS and you want that media instead, emulate screen before generating the PDF:

await page.EmulateMediaAsync(new() { Media = Media.Screen });
await page.PdfAsync(new() { Path = "screen-layout.pdf" });

Test both modes if the web page has separate print styles. Browser output can change substantially when print rules hide navigation, alter colors, or adjust layout.

Rank #4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
  • Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
  • EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
  • READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
  • CREATE, COMBINE, SCAN and COMPRESS PDFs.
  • FILL forms & Digitally Sign PDFs. Work with Digital certificates

Set page dimensions and margins

Playwright’s PDF options accept unit-bearing values for width, height, and margins. Values without units are interpreted as pixels. Specify units explicitly to avoid ambiguity, and validate page breaks using representative content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

await page.PdfAsync(new()
{
  Path = "letter.pdf",
  Format = "Letter",
  PrintBackground = true,
  Margin = new() { Top = "0.5in", Bottom = "0.5in", Left = "0.6in", Right = "0.6in" }
});

Use a paper format or explicit dimensions that match the recipient’s needs. Background printing is useful when the design depends on colored backgrounds, but can increase output size. Consult the PDF API documentation for the available options in your package version.

Make output dependable in production

  • Wait for the actual content. For client-rendered pages, wait for a completion selector or application signal, then verify the generated PDF contains the expected content.
  • Check fonts and assets. Confirm that fonts, images, stylesheets, and scripts are reachable from the renderer’s runtime. Relative paths that work in a developer’s browser may fail in a container or when rendering an HTML string.
  • Test pagination. Validate long tables, headings near page breaks, page dimensions, and print-specific CSS with representative documents rather than a short sample alone.
  • Plan for browser deployment. Include browser binaries and required OS dependencies in the deployment process; the Playwright NuGet dependency is not the whole runtime setup.
  • Handle failures explicitly. Set an application-appropriate timeout, record navigation failures, and avoid returning partial or stale files after a failed render.
  • Manage concurrent work deliberately. Browser startup and page rendering use runtime resources. Measure your own workload before choosing concurrency, reuse, or scaling policies; the cited documentation does not establish a universal throughput figure.
  • Review sensitive inputs. If your application renders user-provided HTML or navigates to caller-supplied URLs, define which resources and destinations are permitted. This is an application security decision, not a PDF option.

Troubleshooting common failures

Symptom Likely cause What to check
Browser launch fails Browser binaries or OS dependencies are missing, or the runtime cannot launch the browser. Repeat the documented Playwright browser installation for the target environment and confirm required system dependencies are present. Setup documentation
PDF is blank or missing data The page was printed before its application finished rendering, or navigation failed. Check the navigation response and wait for a page-specific ready selector before calling PdfAsync.
Images or styles are absent Asset URLs cannot be resolved or accessed from the renderer. Use valid absolute URLs or correct relative base paths; verify network access and file permissions. For IronPDF, its renderer API documents a base URL option for relative assets. IronPDF API
Layout differs from the browser view PDF generation uses print media by default, or the site applies print-specific CSS. Use print rules intentionally, or emulate screen media before generating the PDF.
Content is clipped or split awkwardly Paper size, margins, long content, or print CSS do not fit the selected pagination. Set explicit dimensions and margins, then inspect page breaks across realistic input lengths.
Output path cannot be written The path is relative to an unexpected working directory or the process lacks permission. Use an absolute destination and ensure the application identity can write there.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a screenshot or PDF of a web page rather than a PDF generated inside your own .NET rendering pipeline, ScreenshotNeo offers a one-request API. It can return a screenshot or PDF and also provides an MCP server for AI agents. See ScreenshotNeo and its API documentation.

One cURL request saves a page as PDF:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=pdf -o page.pdf

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use your API key and target URL. The API’s format options are documented at the linked docs page; set the requested PDF output option as shown for the current API.

Best Value
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
  • ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
  • MAXIMUM FUNCIONALITY – create interactive forms, compare PDFs, bates numbering, find and replace text or colors, convert documents, OCR engine, comment, highlight, fill out and print forms, document protection and others
  • EASY TO INSTALL AND USE – well-structured user-interface, in-program instructions, free tech support whenever you need it
  • GREAT VALUE FOR MONEY - why spend a fortune if you can have maximum functionality at a reasonable price - this also fits the requirements of companies very well
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.
  • The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Which C# option should you use?

Use Playwright when browser-based HTML/CSS rendering and browser automation control fit your application, and account for browser installation in deployment. Consider PuppeteerSharp for a similar Chromium automation workflow, or IronPDF if an integrated commercial renderer better suits your team after you verify its license and runtime requirements. Choose QuestPDF when you want to construct the document using C# layout APIs rather than convert existing HTML. For any option, validate fonts, assets, scripts, pagination, and output against the environment and documents you actually plan to use.

Frequently Asked Questions

Does Playwright for .NET convert an HTML string directly to PDF?

Yes. Set the page content with `SetContentAsync` and call `PdfAsync` to generate the PDF.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use screen CSS instead of print CSS?

Yes. Call `EmulateMediaAsync` with screen media before `PdfAsync`; print media is the default.

Is QuestPDF an HTML-to-PDF converter?

The cited QuestPDF examples use code-first PDF composition, not HTML conversion.

Quick Recap

Bestseller No. 1
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99
Bestseller No. 3
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Edit text and images without jumping to another app.; Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
$239.88
Bestseller No. 4
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.; EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
$99.99
Bestseller No. 5
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
$29.99

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.