To generate a PDF from HTML in C#, use PuppeteerSharp to launch headless Chrome, load a URL or HTML string, wait for the content and fonts your page needs, then call PdfAsync. PDF generation is documented as supported only in Chrome headless, and it uses print CSS by default.
Install PuppeteerSharp and prepare Chrome
Add the NuGet package to your project:
dotnet add package PuppeteerSharp
Check the package version and target framework you plan to use before adopting code: compatibility changes over time. The NuGet listing showed PuppeteerSharp 25.12.0 on October 3, 2026; check the NuGet package page for the current release and framework targets.
As an Amazon Associate I earn from qualifying purchases.
In the documented BrowserFetcher workflow, download a compatible browser, launch headless Chrome, and dispose of browser and page resources when the work is complete. PuppeteerSharp’s project site lists Windows, macOS, and Linux support; package instructions call out an X-server requirement on Linux. Those broad platform statements do not establish that every framework, browser build, or container image will work without additional setup, so validate the exact deployment environment. See the PuppeteerSharp project site and package instructions.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Generate a PDF from an HTML string
This example follows the documented download, launch, content, font-readiness, and PDF sequence. Replace the sample markup with your own HTML and verify API symbols against the installed package version.
#1 Best Overall
- PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
- QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
- VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
- INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
- EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
using PuppeteerSharp;
var html = "<!doctype html><html><head><meta charset='utf-8'><title>Report</title></head><body><h1>Monthly report</h1><p>Generated from HTML.</p></body></html>";
var fetcher = new BrowserFetcher();
await fetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(
new LaunchOptions { Headless = true });
await using var page = await browser.NewPageAsync();
await page.SetContentAsync(html);
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
await page.PdfAsync("output.pdf", new PdfOptions
{
Format = PaperFormat.A4,
PrintBackground = true
});
The font wait matters: the official example warns that omitting it might result in no text rendered in the PDF. For remotely hosted fonts, allow for their network loading as well; readiness should reflect the assets and rendering behavior of your own page. The repository’s example uses network-idle waiting with navigation where appropriate. See the PuppeteerSharp repository examples.
Generate a PDF from a URL
For an existing page, navigate instead of setting markup. If the page fills in data asynchronously, wait for a meaningful selector or application-specific condition before printing; a completed navigation alone may not mean the report is ready.
using PuppeteerSharp;
var fetcher = new BrowserFetcher();
await fetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(
new LaunchOptions { Headless = true });
await using var page = await browser.NewPageAsync();
await page.GoToAsync("https://example.com/report");
await page.WaitForSelectorAsync(".report-ready");
await page.EvaluateExpressionHandleAsync("document.fonts.ready");
await page.PdfAsync("report.pdf", new PdfOptions
{
Format = PaperFormat.A4,
PrintBackground = true
});
Choose a selector that appears only when the information you need is present. PuppeteerSharp’s repository demonstrates WaitForSelectorAsync; the right readiness condition is specific to the page.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
- FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
- ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
- READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
- WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
- OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)
Choose print styling and PDF options
PdfAsync uses print CSS media by default. If the intended PDF should reflect screen styles, call EmulateMediaTypeAsync(MediaType.Screen) before PDF generation. Chrome headless is the documented supported mode for generating PDFs. See the IPage API documentation.
PdfOptions exposes paper size or dimensions, orientation, margins, page ranges, background printing, CSS page-size priority, outlines, and header/footer templates. Documented defaults include backgrounds off, landscape off, margins set to none, header/footer disabled, and CSS page size not preferred. When Format is specified, it takes priority over explicit width and height. See PdfOptions API documentation.
- Paper and dimensions: Set a format such as
PaperFormat.A4, or specify width and height. Do not expect explicit dimensions to override a setFormat. - Orientation and margins: Set landscape orientation or margins when the document needs them; the documented defaults are portrait and no margins.
- Backgrounds: Set
PrintBackground = trueif background colors or images are part of the design. The default is false. - Page ranges: Use the page-range option when only selected pages should be emitted.
- CSS page size: Enable preference for CSS
@pagesize when that should take priority over the PDF options’ paper selection. - Headers and footers: Enable templates if you need them. The documented template classes include
date,title,url,pageNumber, andtotalPages. - Outlines: The API describes outline generation as also tagging the PDF for accessibility, but qualifies that it currently works only in old headless mode. Verify behavior in your deployed browser and package before relying on tagged output.
For a PDF file, use PdfAsync(path). If the surrounding application needs bytes or a stream instead, the API also documents PdfDataAsync and PdfStreamAsync. Confirm their signatures for your package version in the IPage API reference.
Rank #3
- FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
- INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
- SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
- EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
- SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning
Wait for the right things without waiting blindly
PDF quality depends on capturing the page after the material it needs is ready. A useful order is to load or set the content, wait for the application-specific content signal, wait for fonts, then print. For a URL with external assets, account for navigation and network completion; for a generated page, wait on a selector or other known readiness condition rather than assuming that setting the HTML finishes later JavaScript work.
- Use
document.fonts.readywhen text depends on web fonts. - Wait for a selector that represents completed data rendering when the page is dynamic.
- Allow for remote assets such as CDN fonts where relevant; network idle may help, but the appropriate condition depends on page behavior.
- Prefer a meaningful readiness condition to an arbitrary delay, which can be either unnecessarily slow or too short.
Troubleshoot common PDF problems
The PDF is missing text or uses fallback fonts
Fonts may not have loaded when printing began. Wait for document.fonts.ready and account for external font requests. The PuppeteerSharp example warns that skipping font readiness might leave text unrendered.
The PDF is blank or contains only part of the page
A navigation can finish before client-side content is populated. Wait for a selector or application-specific ready state before calling PdfAsync. If using SetContentAsync, check whether scripts or external resources continue to update the document afterward.
Rank #4
- Scanner type: Document
- Connectivity technology: USB
- With Auto Scan Mode, the scanner automatically detects what you're scanning
- Digitize documents and images
The PDF looks different from the browser window
Print media is the default for PDF generation, so print-specific CSS may apply. If you want screen styles, call EmulateMediaTypeAsync(MediaType.Screen) before printing.
Background colors or images are missing
Background printing is disabled by default. Set PrintBackground = true when the output needs CSS backgrounds.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsChrome fails to launch, especially on Linux
Check that the downloaded browser build is compatible with the package and target environment, then verify runtime dependencies in the actual host. PuppeteerSharp’s package instructions call out an X-server requirement on Linux and link to troubleshooting guidance. A generic OS support statement is not a guarantee for every container or serverless environment; the available sources do not establish a universal deployment recipe.
Best Value
- OUR MOST ADVANCED SCANSNAP. Large touchscreen, fast 45ppm double-sided scanning, 100-sheet document feeder, Wi-Fi and USB connectivity, automatic optimizations, and support for cloud services. Upgraded replacement for the discontinued iX1600
- CUSTOMIZABLE. SHARABLE. Select personalized profiles from the touchscreen. Send to PC, Mac, mobile devices, and clouds. QUICK MENU lets you quickly scan-drag-drop to your favorite computer apps
- STABLE WIRELESS OR USB CONNECTION. Built-in Wi-Fi 6 for the fastest and most secure scanning. Connect to smart devices or cloud services without a computer. USB-C connection also available
- PHOTO AND DOCUMENT ORGANIZATION MADE EFFORTLESS. Easily manage, edit, and use scanned data from documents, receipts, photos, and business cards. Automatically optimize, name, and sort files
- AVOIDS PAPER JAMS AND DAMAGE. Features a brake roller system to feed paper smoothly, a multi-feed sensor that detects pages stuck together, and skew detection to prevent paper damage and data loss
Or skip the browser setup
If you need a screenshot or PDF from a URL without managing a local browser, ScreenshotNeo provides a website screenshot API and MCP server. For the screenshot API, one GET request can return a PNG, JPEG, WebP, or PDF. The example below uses the supplied cURL pattern with a PDF output format:
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
See the ScreenshotNeo API documentation for request options. Cookie banners are accepted or removed before capture, and newsletter popups and chat widgets are removed; individual cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and 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 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFrequently Asked Questions
Can PuppeteerSharp generate a PDF in a non-Chrome browser?
The PuppeteerSharp API documents PDF generation as currently supported only in Chrome headless.
Does PuppeteerSharp require an installed Chrome browser?
The documented BrowserFetcher workflow downloads a compatible browser before launch. Confirm the browser and runtime dependencies required by your chosen package version and deployment host.
Can I return PDF data without writing a file?
Yes. The IPage API documents PdfDataAsync and PdfStreamAsync as alternatives to PdfAsync(path).
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.
Recommended Free Tools




