Use CefSharp’s browser-level PrintToPdfAsync with a PdfPrintSettings object, set an explicit paper size, and leave PreferCssPageSize set to false. That default scales the rendered page to the selected paper, which is usually the correct “fit to page” behavior. Set it to true only when the document’s CSS @page dimensions should determine the PDF size.
The complete implementation is version-sensitive: CefSharp releases expose different property names, signatures, and measurement units. Check the API reference matching the package installed in your project before copying values into production.
Print a CefSharp browser to a PDF file
The simplest route is the browser-level method:
using CefSharp;
using CefSharp.WinForms;
using System.Threading.Tasks;
public async Task<bool> SaveBrowserAsPdfAsync(ChromiumWebBrowser browser, string outputPath)
{
var settings = new PdfPrintSettings
{
Landscape = false,
PaperWidth = 8.27,
PaperHeight = 11.69,
PreferCssPageSize = false,
PrintBackground = true,
DisplayHeaderFooter = false
};
bool saved = await browser.PrintToPdfAsync(outputPath, settings);
if (!saved)
{
// The path may be unwritable, or Chromium may have failed to create the PDF.
return false;
}
return true;
}
PrintToPdfAsync returns a Boolean. Do not assume that an awaited call means a file was written; check the result and handle a false value. The official WinForms pattern also checks this result and reports a write-permission problem when saving fails.
Call it after the page is ready
Invoke the method only after navigation has completed and the content you need has rendered. If the page builds its layout or loads images asynchronously, wait for that application-specific condition before starting PDF generation. Otherwise, the PDF can contain an early or incomplete layout even though the API call succeeds.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- 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
Use a writable, deterministic path
Pass an absolute path when possible. Ensure the directory exists and that the process identity has write permission. In desktop applications, a user-selected path from a save dialog is generally safer than a protected application directory.
How CefSharp fits content to paper
Fit behavior is controlled primarily by CSS-page-size preference and the physical paper dimensions.
Keep CSS page size preference disabled for automatic fitting
With PreferCssPageSize = false, CefSharp scales the rendered content to fit the configured paper size. This is the default documented behavior. It is the setting to use when a web page is wider than the PDF sheet or when you want predictable output based on your configured paper dimensions.
Set PreferCssPageSize = true only when the page’s CSS @page rule should control the output dimensions. A page that declares a custom CSS size can therefore produce a PDF that does not match your PaperWidth and PaperHeight expectations.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteSet paper width and height explicitly
Specify both dimensions rather than relying on defaults. The sample uses 8.27 by 11.69, the dimensions commonly associated with A4, but the property units are version-dependent in CefSharp browser settings. Confirm the installed package documentation before treating those numbers as inches, millimetres, or another unit.
Rank #2
- 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⁴
Change orientation for wide pages
Use Landscape = true when the page is wider than it is tall. You can also swap the paper dimensions yourself, but do not do both accidentally; choose one consistent orientation strategy.
Control printable margins
Margins affect the usable area and can be the difference between a clean fit and clipped content. CefSharp versions expose margin settings through PdfPrintSettings, including a margin mode and individual top, bottom, left, and right values. The exact units and property availability vary by version. If the default printable area leaves excessive whitespace or clips an edge, select the custom margin mode and set every side explicitly.
Backgrounds, headers, footers, and page ranges
Print CSS background graphics
PrintBackground = true includes CSS background colors and images. Leave it false when you need an ink-saving, mostly text PDF. Background rendering can materially increase output size when a page uses large images or full-bleed colors.
Add generated headers and footers
DisplayHeaderFooter = true enables Chromium’s generated header and footer templates. The DevTools API supports templates containing the classes date, title, url, pageNumber, and totalPages. Use the DevTools route when you need explicit template control rather than the browser-level convenience method.
Restrict output to selected pages
Page ranges are available through the DevTools print-to-PDF command. Ranges are one-based strings such as 1-5, 8, 11-13. The DevTools API also exposes ignoreInvalidPageRanges, allowing you to choose whether invalid ranges are rejected or ignored.
Rank #3
- 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.
Use the DevTools print-to-PDF route
CefSharp also exposes Chromium DevTools Protocol methods named Page.PrintToPDFAsync and PageClient.PrintToPDFAsync. This route is useful when you need options that are more explicit or granular than the browser-level settings object.
// Illustrative shape; confirm the exact signature for your CefSharp package.
var pdf = await browser.GetDevToolsClient()
.Page.PrintToPDFAsync(
landscape: false,
displayHeaderFooter: false,
printBackground: true,
paperWidth: 8.27,
paperHeight: 11.69,
marginTop: 0.25,
marginBottom: 0.25,
marginLeft: 0.25,
marginRight: 0.25,
preferCSSPageSize: false,
pageRanges: "1-5, 8",
ignoreInvalidPageRanges: false);
// Depending on the version and transfer mode, write the returned data
// or consume the returned stream according to that API's contract.
DevTools signatures use nullable numeric parameters in some releases, and the documented paper and margin measurements are inches. Other releases expose a stream transfer mode instead of returning all data directly. The browser-level method saves to a path; the DevTools method returns a response or stream that your code handles. Check the reference for your exact package.
Browser-level versus DevTools printing
| Concern | browser.PrintToPdfAsync |
DevTools Page.PrintToPDFAsync/PageClient.PrintToPDFAsync |
|---|---|---|
| Basic workflow | Pass a path and PdfPrintSettings; CefSharp writes the file. |
Call the protocol method and handle its response or stream. |
| Configuration style | Properties such as orientation, paper size, margins, backgrounds, and CSS-size preference. | Method parameters, including page ranges, templates, nullable values, and transfer mode. |
| Best fit | Applications that need a straightforward PDF file. | Applications that need page selection, custom header/footer handling, or response-level control. |
| Version caution | Property names and units differ between package generations. | Signatures and nullable parameter behavior differ between package generations. |
Version and unit checks before shipping
CefSharp API pages are versioned. The documented examples associated with PdfPrintSettings 108.4.130, Page.PrintToPDFAsync 85.3.121, and PageClient.PrintToPDFAsync 113.3.50 do not represent one universal signature. A property that exists in one generation may be renamed, moved, or measured differently in another.
- Read the installed CefSharp package version from your project file or NuGet assets.
- Open the matching API reference and verify
PdfPrintSettingsproperty names, margin units, and paper-size units. - Verify the DevTools method’s parameter order, nullable types, return type, and transfer mode.
- Generate a test PDF with a ruler-like layout and inspect all four edges before deploying.
Troubleshooting clipped, blank, or incorrectly scaled PDFs
The PDF is clipped on the right or bottom
- Confirm
PreferCssPageSize/preferCSSPageSizeis false when you want automatic scaling. - Set paper width and height explicitly and choose landscape for wide content.
- Reduce or explicitly set all four margins; the default printable area may be smaller than expected.
- Check for fixed-width CSS, positioned elements, or content that intentionally overflows its page.
The page is tiny with large empty margins
- Inspect the page’s
@pagerule. If it declares a size that you do not want, keep CSS-page-size preference false. - Check that your numeric values use the units expected by your installed CefSharp version.
- Remove an unnecessarily large custom margin.
Background colors or images are missing
Set PrintBackground = true or printBackground: true. Also verify that the resources have finished loading before printing and that the page does not apply print-specific CSS that hides them.
Headers or footers do not appear
Enable DisplayHeaderFooter/displayHeaderFooter. For custom text, use the DevTools template parameters and the supported placeholder classes rather than assuming normal page DOM content becomes a PDF header.
Rank #4
- 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
Only part of the document appears
Do not print until the page has completed its own data and image loading. If you intentionally supplied a DevTools pageRanges value, remember that ranges are one-based and comma-separated.
PrintToPdfAsync returns false
- Check that the output directory exists.
- Check write permissions for the account running the application.
- Ensure another process is not locking the destination file.
- Log the selected path and retry with a known-writable temporary directory.
- If the failure persists, verify that the browser has not been disposed and that Chromium initialization completed successfully.
Performance and reliability considerations
- Wait for the real rendering state: navigation completion alone may not mean that JavaScript data, fonts, or lazy images are ready.
- Keep output settings deterministic: explicit paper dimensions, orientation, margins, and background behavior make automated comparisons more reliable.
- Manage large pages: printing full, image-heavy documents with backgrounds can consume substantial memory and produce large files. Consider page ranges or a print-specific stylesheet.
- Test representative layouts: include narrow text pages, wide tables, long documents, images, custom fonts, and pages with CSS
@pagerules. - Handle the Boolean result and exceptions: treat a failed save as an operational error, not as a successful print.
Or skip the browser setup
If your requirement is simply to obtain a clean screenshot or PDF from a URL, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.
See the ScreenshotNeo API documentation for all options, including PDF paper size, margins, landscape mode, page ranges, waiting conditions, custom headers and cookies, CSS and JavaScript, resource blocking, signed links, asynchronous jobs, bulk capture, caching, and usage reporting.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
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}`);
ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
Frequently Asked Questions
Which CefSharp API should a new desktop application start with?
Start with the browser-level method when saving a normal PDF file is all you need. Use the DevTools route when you require page ranges, custom header/footer templates, or response and stream handling.
Why must I verify the API reference for my exact package version?
CefSharp releases expose different signatures, property sets, and measurement units. Examples from one version are not guaranteed to compile or measure the same way in another.
Can a page’s CSS override my configured paper size?
Yes. Setting the CSS-page-size preference to true allows the document’s CSS @page dimensions to control the PDF; leave it false for paper-based fitting.
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.

