October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Render a Webpage to PDF in a .NET Application

Use Playwright for .NET to turn a webpage or generated HTML into a PDF, with control over print styling, paper size, margins and backgrounds.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a browser-rendered PDF in .NET, use Playwright for .NET: open the page and call Page.PdfAsync. It returns PDF bytes and can also save to a file. By default, PDF generation uses print media, so decide whether you want print styling or screen styling before choosing paper size, margins and background options.

Render a webpage to PDF with Playwright for .NET

Install the Playwright .NET package and its supported browser, then navigate to the page and save the PDF. This example uses Chromium and A4 paper; adjust the browser installation and package setup to match the current Playwright for .NET documentation.

As an Amazon Associate I earn from qualifying purchases.

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();

await page.GotoAsync("https://example.com");
await page.PdfAsync(new PagePdfOptions
{
    Path = "page.pdf",
    Format = "A4",
    PrintBackground = true
});

PdfAsync can save directly using the Path option or return PDF bytes when you need to store or process the result yourself. See the Playwright for .NET Page PDF API for the current API details.

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

Render HTML you already have

If the application generates HTML instead of starting with a URL, assign it to the page with SetContentAsync, then create the PDF:

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • 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
await page.SetContentAsync("<html><body><h1>Invoice</h1></body></html>");
await page.PdfAsync(new PagePdfOptions
{
    Path = "invoice.pdf",
    Format = "A4",
    PrintBackground = true
});

Choose print or screen styling

Playwright generates PDFs using print media by default. A page’s print-specific CSS can therefore change or hide content compared with what a visitor sees in a browser. If the PDF must use screen styles, emulate screen media before calling PdfAsync:

await page.EmulateMediaAsync(new PageEmulateMediaOptions
{
    Media = Media.Screen
});

await page.PdfAsync(new PagePdfOptions { Path = "screen-style.pdf" });

Use print media for documents designed for paper, such as pages with print styles or page-break rules. Use screen media when matching the on-screen layout is the requirement. Test pages with both responsive and print CSS rather than assuming the two modes are interchangeable.

Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • 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)

Set page size, margins and output options

Choose PDF settings deliberately; defaults may not match the document’s intended layout. Playwright documents these relevant options:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Format selects a standard paper size such as A4 or Letter. Alternatively, set explicit width and height with units.
  • Margin sets page margins using CSS-style units.
  • PrintBackground is off by default. Set it to true if background colors or images are part of the intended design.
  • Scale adjusts output scale from 0.1 to 2.
  • PageRanges selects which pages to include.
  • PreferCSSPageSize lets CSS @page sizing take priority when enabled. Without it, CSS page sizing does not take precedence over the PDF options.
  • Tagged output is available as an option; consult the API documentation for its current name and behavior.

For example, to use Letter paper with explicit margins and background graphics:

Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer
await page.PdfAsync(new PagePdfOptions
{
    Path = "report.pdf",
    Format = "Letter",
    PrintBackground = true,
    Margin = new Margin
    {
        Top = "0.5in",
        Right = "0.5in",
        Bottom = "0.5in",
        Left = "0.5in"
    }
});

If the document’s CSS defines its own page size, set PreferCSSPageSize = true when that CSS should control the output. Consult the API reference for the exact option types in the Playwright version you install.

Make sure content is ready before capture

PDF generation can begin before a page’s asynchronous content, images or fonts are ready. Navigate using an appropriate readiness condition for the page, wait for required content or a known selector, and inspect the result when output is missing or incomplete. For pages using web fonts, PuppeteerSharp’s PDF example recommends waiting for document.fonts.ready; this highlights a font-readiness concern, but the correct wait strategy depends on the page and rendering API.

Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 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. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management

When another renderer may fit better

Option What the cited documentation establishes Consider
Playwright for .NET Browser automation API with Page.PdfAsync, print-oriented PDF options and HTML content support. API reference A browser-driven workflow with explicit control over media, paper size and output settings.
PuppeteerSharp Its NuGet page describes a .NET 8 version and a .NET Standard 2.0 flavor. Its documentation’s PDF example waits for document.fonts.ready. NuGet package · Project documentation Check the target frameworks for the exact release and account for page-resource and font readiness.
wkhtmltopdf The project page identifies it as an HTML-to-PDF tool using Qt WebKit. The cited page does not establish its modern CSS compatibility or current maintenance status. Project page Validate your pages and deployment requirements before choosing it; the available source does not establish comparative fidelity.

The available documentation does not provide a controlled fidelity or speed comparison among these renderers. Test representative pages—especially complex CSS, fonts, charts and page breaks—before selecting one for a production workload. Commercial .NET PDF SDKs are another category; vendor documentation establishes HTML webpage rendering capability, but verify current framework support, deployment constraints and licensing directly with the vendor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common PDF problems

  • The PDF looks different from the browser: print media is the default. Use EmulateMediaAsync with screen media if the PDF should follow screen styles, or adjust the print stylesheet.
  • Background colors or images are missing: enable PrintBackground.
  • The page size ignores CSS @page rules: enable PreferCSSPageSize if CSS sizing should take precedence, and check that the page’s print CSS defines the intended size.
  • Text or images are absent: wait for the required page content and resources before generating the PDF. For web fonts, investigate font readiness; PuppeteerSharp’s example specifically waits for document.fonts.ready.
  • Content is clipped or scaled unexpectedly: verify the selected paper format, explicit dimensions, margins and scale together. Check page-break behavior in print CSS.

Or skip the browser setup

If your .NET application needs a screenshot or PDF from a URL without managing a browser yourself, ScreenshotNeo offers a one-request API. A GET request to its API returns an image or PDF; for example, save a PDF response as a file:

Best Value
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -d format=pdf -o page.pdf

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers say the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents. The free plan includes 1,000 shots per month without a 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.

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.