October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Print PDFs with Headless Chrome and C# Chrome DevTools

A practical C# guide to generating PDFs with headless Chrome using PuppeteerSharp or Page.printToPDF, including print styling, geometry, command-line capture, and common fixes.

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.

In C#, the simplest documented route to a PDF from headless Chrome is PuppeteerSharp’s IPage.PdfAsync method. For lower-level control, Chrome DevTools Protocol provides Page.printToPDF. Choose the library when you want a concise C# API; use CDP directly when your client needs protocol-level options. In either case, check the API and experimental options against the Chrome and library versions you deploy.

Choose a C# approach

PuppeteerSharp wraps Chrome’s page-printing capability in a page-level API. Its documentation provides PdfAsync overloads for writing a PDF to a path, PdfDataAsync for receiving bytes, and PdfStreamAsync for a stream. The lower-level protocol method is Page.printToPDF, described by the Chrome DevTools Protocol as “Print page as PDF.”

As an Amazon Associate I earn from qualifying purchases.

Approach Best fit Output What to check
PuppeteerSharp Typical C# applications that want a page-oriented API. File, byte array, or stream, depending on the method. Match PuppeteerSharp APIs and options to the package version and Chrome build you run.
Direct CDP Applications already using a Chrome DevTools Protocol client and needing protocol controls. Protocol response; handling and decoding depend on the client. Generated types and method-call syntax vary by client. Verify experimental fields against the deployed Chrome version.

The documentation establishes these API shapes and protocol controls, but does not establish a universal performance advantage for either approach.

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

Print a page to a PDF file with PuppeteerSharp

Add the PuppeteerSharp NuGet package to your project, then use its documented page API. This example writes a PDF to a path; it does not claim a particular package or Chrome version, so use the API signatures supported by the versions you pin.

#1 Best Overall
Sale
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
using PuppeteerSharp;

var url = "https://example.com/";

await new BrowserFetcher().DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true
});

await using var page = await browser.NewPageAsync();
await page.GoToAsync(url);
await page.PdfAsync("output.pdf");

PdfAsync uses print CSS media by default. If the document should reflect screen styles instead, set the media type before generating the PDF:

await page.EmulateMediaTypeAsync(MediaType.Screen);
await page.PdfAsync("output.pdf");

Use PdfDataAsync when the next step needs a byte array, or PdfStreamAsync when it can consume a stream. These are alternatives to saving directly to a file, not different rendering modes.

Control page size, margins, and print appearance

Chrome’s Page.printToPDF protocol method exposes the print controls below. PuppeteerSharp provides PDF options as well, but confirm exact property names and availability in the package version you use rather than copying protocol field names blindly into a library object.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Control Effect and documented default
Orientation Chooses portrait or landscape page orientation.
Scale Scales printed content; the protocol default is 1.
Paper width and height Set page dimensions. The protocol defaults are 8.5 by 11 inches.
Margins Set page margins; the protocol default is 1 cm.
Page ranges Restrict output to selected pages; by default, all pages are printed.
Print background Includes background graphics and colors. This is false by default, so enable it when the design relies on backgrounds.
Header and footer Displays print header/footer templates when enabled; display is false by default. Supported placeholder classes include date, title, url, pageNumber, and totalPages.
preferCSSPageSize When enabled, lets CSS @page size take precedence over protocol paper dimensions. Otherwise, content is scaled to fit the specified paper.
Transfer mode Controls how PDF data is transferred by the protocol. Check support and behavior in the protocol version exposed by the Chrome build and CDP client.

Some protocol fields are marked experimental in the live reference. Their presence in documentation does not guarantee support in every Chrome build or generated client.

Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Use the Chrome command line when C# is not required

Chrome’s headless command-line interface can print a target page without an application wrapper:

chrome --headless --print-to-pdf=output.pdf https://example.com/

Chrome documents --print-to-pdf as saving a PDF in the working directory. Add --no-pdf-header-footer to suppress the date/time header and URL/page-number footer:

chrome --headless --print-to-pdf=output.pdf --no-pdf-header-footer https://example.com/

The older flag name --print-to-pdf-no-header was used previously, so check compatibility if you target older Chrome versions. For pages with timing-dependent content, Chrome’s CLI documentation describes --timeout as a maximum wait after which it captures even if loading continues, and --virtual-time-budget as a way to fast-forward time-dependent JavaScript such as timers. These are CLI flags; do not assume they are PuppeteerSharp options.

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

Account for print CSS and loading behavior

Print styles versus screen styles

PDF generation through PuppeteerSharp uses print media by default. This means CSS inside @media print can change or hide content in the PDF. If the desired result is the screen presentation, call EmulateMediaTypeAsync(MediaType.Screen) before printing.

Rank #3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.

Pages that render after navigation

A navigation call and a finished PDF do not necessarily mean an application has completed every delayed update. If important content appears only after scripts or timers run, decide how much waiting the application requires and verify the resulting document. The Chrome CLI timing flags can help in CLI workflows; the cited material does not establish equivalent PuppeteerSharp controls or defaults, so use that library’s documentation for its wait APIs.

Backgrounds and page geometry

Check the PDF with backgrounds explicitly enabled if color blocks, logos, or other graphics disappear. For page-size mismatches, determine whether geometry is coming from CSS @page or protocol paper dimensions and configure preferCSSPageSize accordingly.

Troubleshoot common PDF problems

  • The PDF uses unexpected fonts, spacing, or hidden elements: inspect the page’s print CSS. If you want screen styling, emulate screen media before calling PdfAsync.
  • Background colors or images are missing: print backgrounds are off by default in the protocol. Enable the background option supported by your PuppeteerSharp version or CDP client.
  • Paper dimensions do not match the site’s CSS: check whether @page should control the size. Set preferCSSPageSize when CSS page size should take precedence; otherwise content is scaled to fit the protocol paper dimensions.
  • Headers or footers appear unexpectedly, or are absent: protocol header/footer display defaults to false. When enabled, inspect the header/footer templates and their placeholder classes; for CLI capture, use the supported suppression flag for the Chrome version in use.
  • Content that loads late is missing: check whether the page is waiting on asynchronous work, timers, or continued loading. The CLI offers timeout and virtual-time controls, but confirm the correct waiting mechanism for your C# library and its version.
  • A protocol option fails or is missing from generated types: verify the Chrome protocol version, the CDP client’s generated types, and whether the field is experimental. Do not assume every documented field exists in every deployed combination.
  • The CLI flag is rejected: check the installed Chrome version and use its supported flag name; the header-suppression flag has had an older name.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Version, reliability, and cost considerations

Chrome’s unified new Headless mode became available in Chrome 112, according to the Chrome Headless documentation. That is a historical availability fact, not a guarantee about which mode a current installation selects. Check the Chrome version and flags in the environment that actually runs the job.

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

The protocol reference is live, and some parameters are experimental. Record the Chrome and PuppeteerSharp versions used by the application, validate output after upgrades, and avoid relying on experimental options without checking their support. The cited documentation provides no comparative throughput, latency, memory, or reliability benchmark, so those should be measured in your own workload rather than inferred from the API choice.

Rank #4
Sale
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art

Or skip the browser setup

If you need a hosted capture rather than managing headless Chrome, ScreenshotNeo is a website screenshot API that can return PNG, JPEG, WebP, or PDF. One GET request can capture a URL; see the ScreenshotNeo API documentation for PDF and other options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture, and each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits cost nothing; response headers identify the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 shots a 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.

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

Frequently Asked Questions

Does PuppeteerSharp print screen CSS by default?

No. It uses print CSS media by default; emulate screen media before PDF generation when you need screen styles.

Which CDP method prints a page to PDF?

Use the Page-domain method Page.printToPDF; the exact invocation depends on the C# DevTools Protocol client.

Can I return PDF bytes instead of saving a file?

Yes. PuppeteerSharp documents PdfDataAsync for bytes and PdfStreamAsync for a stream.

Quick Recap

Bestseller No. 3
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
HP Smart Tank 5000 Ink Tank Printer | 2 Years of Ink Included | All-in-One
PREMIUM SUPPORT - Strong technical expertise to solve issues faster; THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
$189.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.

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 *

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.