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

Use Chromium’s Playwright page.pdf() to export a rendered page, and control pagination with print CSS. By default, PDF generation uses print media; use @page for paper size and margins, and apply page-break rules selectively so short elements stay together without forcing long sections into awkward gaps.

Generate a PDF with Playwright

Install Playwright and its supported Chromium browser, then navigate to the page and call page.pdf(). The documented Playwright PDF export path is Chromium-only. Keep the Playwright package and browser binaries aligned using Playwright’s browser-install workflow; the official guidance is at https://playwright.dev/docs/browsers.

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 app renders asynchronously, wait for its own ready signal here.
    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();
  }
})();

page.pdf() returns a PDF buffer and can also save directly to a path. The example uses path to write page.pdf. The Playwright PDF API reference documents media behavior, paper sizing, margins, scale, backgrounds, headers and footers, and other export options.

Wait for the page your application actually needs

waitUntil: 'networkidle' waits for network activity to settle, but it does not prove that every application has finished rendering. If the page fetches data, builds charts, or loads content after that point, wait for an application-specific signal before exporting, such as a report container becoming visible or a known “ready” state. Use a selector wait or an explicit application signal that corresponds to completed content rather than adding an arbitrary delay as a substitute.

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

Choose print media or screen media deliberately

Playwright generates PDFs using print CSS media by default. That is usually the right choice for a document: create an @media print stylesheet with print-specific layout, typography, and visibility rules. To render screen styles instead, call await page.emulateMedia({ media: 'screen' }) before page.pdf(). Switching to screen media is not a fix for missing print styles; it changes which stylesheet rules apply.

Set paper size and margins without conflicting controls

Use CSS @page rules for document-wide paper and margin settings, or set paper dimensions and margins through the PDF options. If CSS should decide the paper size, set preferCSSPageSize: true; otherwise, Playwright’s PDF API paper-size settings take precedence by default. Avoid supplying conflicting CSS and API values without deciding which should win.

@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;
  }
}

With the CSS above and preferCSSPageSize: true, the @page size is preferred over the API’s format, width, or height. If you instead want the API to control paper size, remove the preference and set the API size and margins intentionally.

Preserve page breaks without creating bad pagination

Let variable-length content flow naturally

For articles and reports whose text or data changes, allow normal pagination and protect only small units that should not split. A figure and its caption, a compact card, or a short table group are good candidates for break-inside: avoid. It is a pagination preference, not a guarantee: if the block is taller than the printable page area, it cannot fit intact.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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)

Force a new page only for deliberate section starts

For chaptered reports, invoices, or other documents where each major section must begin on its own page, apply break-before: page to the section wrapper. break-after: page can instead end a section with a page break. Forced boundaries make starts more predictable, but can leave conspicuous blank space when preceding content changes. The CSS property applies only when the element generates a box in normal flow.

Keep headings with what follows

A print rule such as break-after: avoid-page on headings discourages a heading from being stranded at the foot of a page. It does not guarantee an exact composition; inspect the generated PDF with the page’s real content and styles.

Pagination approach Best for Trade-off
Natural print pagination with selective break-inside: avoid Articles and reports with variable content Flexible, but exact page starts can vary with content and fonts.
Explicit break-before: page for major sections Chaptered reports, invoices, and documents with required section starts Predictable boundaries, but may create whitespace and become brittle as content changes.

Do not put break-inside: avoid on an entire long article or section. If the protected region cannot fit on one page, the browser must still fragment it or produce poor pagination. Narrow the protected wrapper to the specific heading-plus-opening text, figure, card, or compact table unit that needs to stay together.

Control colors, backgrounds, and page furniture

  • Backgrounds: set printBackground: true when the PDF needs CSS background colors or images. Chromium modifies colors for print output by default; use -webkit-print-color-adjust: exact in print styles when authored colors should be preserved, then verify the result.
  • Headers and footers: Playwright’s headerTemplate and footerTemplate can include injected classes for date, title, URL, page number, and total page count. Template scripts are not evaluated, and the page’s styles are not visible inside these templates.
  • Scale and dimensions: use the API’s scale and paper sizing options when the document requires them, but avoid using scale to conceal a layout that should instead be corrected in CSS.

Review the PDF in the target runtime

CSS break properties express layout preferences; they do not promise that every page will match a mockup under all content, fonts, and browser versions. Open the actual exported PDF and check:

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
  • Headings left at the bottom of a page without enough following content.
  • Figures, cards, or table units split despite a keep-together rule.
  • Clipped text, content outside margins, unexpectedly large gaps, or forced breaks creating near-empty pages.
  • Page count, paper size, margin consistency, and whether backgrounds and colors appear as intended.

When investigating a layout regression, record both the Playwright and Chromium versions. PDF behavior can vary across browser versions; use Playwright’s browser-install workflow and keep the installed browser aligned with the Playwright version you run.

Troubleshoot common PDF pagination problems

The PDF looks like print styles are missing

This is expected if the page relies only on screen CSS: PDF generation uses print media by default. Add or correct @media print rules. Emulate screen media only if the intended document should actually use screen styles.

A section does not start on a new page

Put break-before: page on the section wrapper and ensure it generates a box in normal flow. A break rule on an element that generates no box has no effect.

A figure or card still splits

Apply break-inside: avoid to the bounded element and verify that it fits within the printable area. The older page-break-inside: avoid is treated as an alias, but new styles should use break-inside.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

The PDF has large blank gaps or odd page starts

Remove broad keep-together rules, reduce the protected unit, or stop forcing a page break where a new page is not required. Let long content paginate naturally; an over-tall block cannot be kept whole on a page.

CSS paper size seems ignored

Check whether preferCSSPageSize is enabled. Its default is false, so API paper-size options take precedence unless you opt into CSS sizing. Also check for conflicting format, width, or height options.

Colors or backgrounds differ from the page

Set printBackground: true for backgrounds and, if authored colors matter, use -webkit-print-color-adjust: exact in print CSS. Inspect the exported file rather than assuming those settings guarantee identical appearance.

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 one-request PDF capture, ScreenshotNeo accepts a URL and returns a PDF. It also offers 63 capture options; see the ScreenshotNeo API documentation for request parameters.

Free tools Windows power users keep installed

One-click scans. No signup required.

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 -o shot.pdf
  • Cookie banners are accepted like a visitor, and 60+ known consent platforms, newsletter popups, and chat widgets are removed before capture; each of those steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.
  • An 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 shots per month without a card; paid plans start at $5 for 3,000 shots.

ScreenshotNeo is made by Yorker Media. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Can Playwright save a page as a PDF in Firefox or WebKit?

The documented Playwright PDF export path uses Chromium; use Chromium for this workflow.

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

No. It is a pagination preference, and a block taller than the printable page area cannot fit intact.

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.