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

Set printBackground: true in Playwright’s page.pdf() options to include a page’s background graphics in its PDF. Playwright uses print CSS media by default; if you need the page’s screen styles, emulate screen media before generating the PDF. For color fidelity, add -webkit-print-color-adjust: exact to the page’s CSS.

Capture a PDF with background colors in JavaScript

In Playwright’s JavaScript API, pass printBackground: true to page.pdf(). The option defaults to false, so without it background graphics are omitted. Playwright’s Page API documents this option.

await page.pdf({
  path: 'page.pdf',
  printBackground: true,
});

This assumes you already have a Playwright page open and ready. path saves the resulting PDF to that file; without a path, page.pdf() returns a PDF buffer you can handle in your application.

Choose print or screen styles

PDF generation uses print CSS media by default. That means @media print rules apply, and the result may differ from the page as it appears in a browser window. To render screen media styles instead, switch media before calling page.pdf():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#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.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'page.pdf', printBackground: true });

Use the default when the document’s print layout is intended. Emulate screen when the PDF should follow the on-screen styles. The media emulation API also accepts print and null; see the Playwright Page API.

Preserve intended colors

Enabling printBackground asks Playwright to print background graphics, but print rendering can also adjust colors. If exact CSS colors matter, add this rule to the page stylesheet:

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)
html {
  -webkit-print-color-adjust: exact;
}

This CSS property addresses print color adjustment; it does not replace printBackground: true. The two settings serve separate purposes: one requests background graphics, and the other asks the browser to preserve the specified colors.

Control paper size and layout

Playwright lets you set paper format or dimensions, orientation, margins, page ranges, and scale in page.pdf(). The documented defaults and interactions are important when the resulting PDF must match a particular page layout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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
Option Behavior
format Defaults to Letter. Supported formats include Letter, Legal, Tabloid, Ledger, and ISO A-series sizes. When supplied, format takes priority over explicit width and height.
width and height Set paper dimensions. Unlabeled values are treated as pixels; supported units include px, in, cm, and mm.
preferCSSPageSize Defaults to false. Set to true for the stylesheet’s CSS @page size to take precedence over PDF width, height, or format options. With the default, content is scaled to fit the chosen paper size.
landscape Choose landscape orientation when the page needs a wider paper layout.
margin Sets page margins; the default is zero.
pageRanges Limits the PDF to specified page ranges.
scale Defaults to 1; documented range is 0.1 to 2.

For example, if the site defines its intended paper dimensions in CSS with an @page rule, set preferCSSPageSize: true. Otherwise, choose a PDF format or dimensions and let Playwright fit the content to them.

Use Python or Java

The corresponding documented option names differ by language. The Python API uses print_background and prefer_css_page_size; the Java API uses setPrintBackground and setPreferCSSPageSize. Consult the language-specific API references for the current method signatures: Python Page API and Java Page 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

These references are labeled “next” documentation and may change. The documented behavior is consistent in describing how to request printed backgrounds, but identical output across browser engines or deployment environments has not been established here.

Troubleshoot missing backgrounds or unexpected layout

  • Backgrounds are missing: Confirm that printBackground: true is set in the PDF options. Its default is false.
  • The PDF looks different from the browser window: PDF generation uses print media by default. Call page.emulateMedia({ media: 'screen' }) before page.pdf() if screen styles are the target.
  • Colors look altered: Add -webkit-print-color-adjust: exact to the page’s CSS when exact colors are required, and keep printBackground: true enabled for background graphics.
  • The CSS paper size is ignored: Set preferCSSPageSize: true if the stylesheet’s @page size should govern. Otherwise, Playwright’s PDF paper options take precedence and content is scaled to fit.
  • The PDF has unexpected scale or margins: Check the selected format, dimensions, margin, and scale options. Format overrides explicit width and height; margins default to zero, and scale defaults to 1.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a URL-to-PDF request without managing a Playwright browser, ScreenshotNeo provides a screenshot API that can return a PDF. For example, this cURL request captures a page as a PDF:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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://stripe.com -d format=pdf -o page.pdf

See the ScreenshotNeo API documentation for PDF parameters and setup. ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. It also has an MCP server with screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Playwright print page backgrounds by default?

No. Set printBackground: true; its default is false.

Does printBackground force exact CSS colors?

No. It requests background graphics. Use -webkit-print-color-adjust: exact for print color adjustment.

Can I use Playwright’s JavaScript API to return a PDF instead of saving a file?

Yes. page.pdf() returns a PDF buffer; the path option saves it to disk.

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

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.