DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Capture Web Pages as PDFs with Playwright and Preserve Page Breaks

A practical guide to Playwright PDF export: configure Chromium, print CSS, paper sizing, page-break rules, and inspect the finished document.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright’s Chromium browser and page.pdf() to export a rendered page. The method uses print CSS by default, so control pagination with @page, break-before, and selective break-inside rules, then inspect the resulting PDF. A CSS break rule is a layout preference, not a guarantee when content cannot fit on a page.

Generate a PDF with Playwright

Playwright’s page.pdf() uses print CSS media by default. Define print-specific layout in CSS, then set the paper size and margins deliberately in the PDF options. The documented PDF export path is Chromium-only; use Chromium rather than Firefox or WebKit for this operation. See the Playwright page.pdf() API reference.

As an Amazon Associate I earn from qualifying purchases.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle' });

    // If the application renders asynchronously, wait for its own
    // readiness signal before exporting. Network idle is not universal proof.
    await page.pdf({
      path: 'page.pdf',
      format: 'A4',
      printBackground: true,
      preferCSSPageSize: true,
      margin: { top: '18mm', right: '16mm', bottom: '18mm', left: '16mm' },
    });
  } finally {
    await browser.close();
  }
})();

Install Playwright and its supported browser binaries using the Playwright installation workflow. Keep the Playwright package and installed browser versions aligned with that workflow, and record both versions when tracking down a PDF layout change.

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

Wait for the page’s actual content

networkidle is a useful navigation condition, but it does not prove that every app has finished rendering. If the page loads charts, client-side content, or images after navigation, wait for an application-specific selector or readiness signal before calling page.pdf(). For example, use await page.locator('#report-ready').waitFor() when the page provides such a marker.

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner | For Computers including PC and Mac Receipt and Document Scanner USB Powered
  • 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

Set print CSS and page breaks

Use @page for paper size and margins, and print media rules for pagination. Keep continuous articles in natural flow; force a new page only where the section boundary is an editorial requirement.

@page {
  size: A4;
  margin: 18mm 16mm;
}

@media print {
  .start-new-page {
    break-before: page;
  }

  .keep-together {
    break-inside: avoid;
  }

  h1, h2, h3 {
    break-after: avoid-page;
  }

  /* Use only when authored colors need to be preserved. */
  .preserve-print-colors {
    -webkit-print-color-adjust: exact;
  }
}

Choose natural flow or a deliberate section start

Approach Use it for Tradeoff
Natural pagination with selective break-inside: avoid Articles and reports whose content length varies Flexible and readable, but page starts can shift with content and fonts.
break-before: page on major sections Chaptered reports, invoices, or documents that require deliberate section starts Predictable boundaries, but can create whitespace and become brittle as content changes.

For a forced break, add break-before: page to a section wrapper that generates a box in normal flow. To end a section on a new page, use break-after: page. A break property has no effect when its target generates no box.

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)

Keep only bounded content together

Use break-inside: avoid on compact units that should stay intact, such as a figure and caption, a card, or a small table row group. You can also apply it to a short wrapper containing a heading and its opening paragraph. Avoid putting it on a long section or article: an element taller than the printable page cannot fit intact and may produce awkward gaps or pagination. The older page-break-inside: avoid is an alias, but new CSS should use break-inside. See the CSS break-inside reference.

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

Choose paper sizing, color, and PDF options

Playwright’s PDF API accepts a paper format or explicit dimensions, margins, scale, and other print controls. Decide whether CSS or the API controls paper size instead of specifying conflicting values. With preferCSSPageSize: true, a CSS @page size takes priority over PDF API format, width, or height. The default is false, so API paper sizing otherwise takes precedence. The API also returns a PDF buffer if you do not save directly to a path.

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
  • Backgrounds: Set printBackground: true when the PDF needs page backgrounds or background graphics.
  • Authored colors: Print rendering may modify colors. Use -webkit-print-color-adjust: exact where exact authored colors matter, and inspect the export.
  • Headers and footers: headerTemplate and footerTemplate support injected classes for date, title, URL, page number, and total pages. Template scripts are not evaluated, and page styles are not visible inside the templates.
  • Screen styling: If the intended output is specifically the screen version, call await page.emulateMedia({ media: 'screen' }) before page.pdf(). For documents, print CSS is usually the appropriate place to define the layout.

Review the exported PDF

CSS expresses pagination preferences; it cannot make an oversized block fit or guarantee identical composition in every runtime. Open the generated PDF in the target viewer and check:

  • Headings stranded at the bottom of a page or separated from their content.
  • Clipped text, figures, tables, or other content at page edges.
  • Large blank areas caused by broad keep-together rules or forced breaks.
  • Page count, paper dimensions, and margins.
  • Backgrounds and colors compared with the intended print design.

When diagnosing a change in layout, record the Playwright and Chromium versions alongside the output. Browser-version differences can affect PDF rendering; keep Playwright updated and install browsers through its documented workflow.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common PDF problems

  • The output does not look like the screen: That is expected by default because page.pdf() renders print media. Add or adjust @media print rules; use page.emulateMedia({ media: 'screen' }) only when screen styles are wanted.
  • A section begins in the wrong place: Put break-before: page on its normal-flow wrapper and confirm the element generates a box. Remove competing or overly broad break rules if they create unwanted space.
  • A figure or card splits across pages: Apply break-inside: avoid to the smallest bounded wrapper that should stay together, then check whether it fits within the printable area.
  • The PDF has large gaps or odd page starts: Remove keep-together rules from long containers, narrow the protected unit, and allow long content to fragment naturally.
  • The CSS paper size appears ignored: Check whether preferCSSPageSize is enabled and whether API format, width, or height settings conflict with the intended @page size.
  • Backgrounds or colors are missing or changed: Set printBackground: true for backgrounds and use -webkit-print-color-adjust: exact when authored colors need preserving. Verify the actual export.
  • PDF export fails in another browser: Use Chromium for Playwright PDF generation; the documented PDF export path is Chromium-only.

Or skip the browser setup

If the goal is a screenshot or PDF rather than custom Playwright print layout, ScreenshotNeo offers a one-request capture API and an MCP server. For a PDF, call its documented endpoint with the PDF output option configured as described in the ScreenshotNeo API documentation. Here is the documented one-call screenshot example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

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

Frequently Asked Questions

Can I use Firefox or WebKit with Playwright to create the PDF?

No. Playwright’s documented PDF export path is Chromium-only.

Does break-inside: avoid guarantee that an element stays on one page?

No. It is an avoidance preference; an element taller than the printable page cannot fit intact.

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.

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
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.