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

Use Puppeteer’s page.pdf() method and let the document’s content flow naturally across the selected paper size. Put page dimensions and intentional breaks in print CSS, then use PDF options for margins, backgrounds, and output format.

The reliable pattern is: wait for your HTML and fonts, apply print media, define an @page rule, avoid fixed-height containers that clip content, and add break-before: page only where a new section must start on a fresh page.

Quick start: generate a multi-page PDF

Install Puppeteer in a Node.js project, create a page, load the HTML, and call page.pdf(). A PDF is not limited to the browser viewport: content that exceeds one paper-sized page is paginated by the print layout engine.

Install Puppeteer

npm install puppeteer

Complete runnable example

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.setContent(`
    <!doctype html>
    <html>
      <head>
        <meta charset='utf-8'>
        <style>
          @page {
            size: A4;
            margin: 16mm;
          }

          * { box-sizing: border-box; }
          body {
            margin: 0;
            color: #202124;
            font: 11pt/1.45 Arial, sans-serif;
          }
          h1, h2, h3 { break-after: avoid; }
          section { margin-bottom: 12mm; }
          .start-new-page { break-before: page; }
          .keep-together { break-inside: avoid; }
          @media print {
            .screen-only { display: none !important; }
          }
        </style>
      </head>
      <body>
        <h1>Quarterly report</h1>
        <section>
          <h2>Overview</h2>
          <p>This content can continue onto the next page when it exceeds the available area.</p>
        </section>
        <section class='start-new-page'>
          <h2>Detailed results</h2>
          <p>This section begins on a new PDF page.</p>
        </section>
      </body>
    </html>
  `, { waitUntil: 'networkidle0' });

  await page.emulateMediaType('print');

  await page.pdf({
    path: 'report.pdf',
    format: 'A4',
    printBackground: true,
    preferCSSPageSize: true,
    margin: {
      top: '16mm',
      right: '16mm',
      bottom: '16mm',
      left: '16mm'
    },
    waitForFonts: true
  });

  await browser.close();
})();

page.pdf() uses print CSS by default. The explicit emulateMediaType('print') call makes that choice visible in the code and is useful when the page was previously rendered with screen media. The PDF API documents format as defaulting to Letter, printBackground as defaulting to false, and preferCSSPageSize as defaulting to false.

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.
#1 Best Overall
Brother DCP-L2640DW Wireless Compact Monochrome Multi-Function Printer, Copy, Scan, Duplex, Mobile Printing
  • BEST FOR SMALL BUSINESSES – Engineered for extraordinary productivity, the Brother DCP-L2640DW Monochrome (Black & White) 3-in-1 combines laser printer, scanner, copier in one compact footprint and delivers high-quality black & white prints
  • FAST PRINTER WITH EFFICIENT SCANNING – Produces documents quickly with print speeds up to 36 ppm(2) and scan speeds up to 23.6/7.9 ipm(3) (black/color). A 50-page auto document feeder(4) allows for convenient, time saving multi-page scanning and copying
  • FLEXIBLE CONNECTION OPTIONS – Easily navigate the changing demands of your business with secure multi-device connectivity via built-in dual-band wireless (2.4GHz / 5GHz) and Ethernet. Or connect locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Print, scan, and manage your wireless printer anytime, from almost anywhere from your mobile device. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(5)
  • CHOOSE BROTHER GENUINE TONER – When it’s time to replace your toner, be sure to choose Brother Genuine TN830 or TN830XL replacement toner. And with Refresh EZ Print Subscription Service, you’ll never worry about running out of toner again and you’ll enjoy savings of up to 50%(6) on Brother Genuine Toner. Get started with Refresh today with a Free Trial(1)

Make content flow across pages instead of clipping

Natural pagination works when the document has ordinary block flow and no ancestor is restricting its height. Check the page for wrappers such as height: 100vh, overflow: hidden, or an application panel intended only for on-screen scrolling. Those styles can make a long report look like one short page or hide everything below a fixed region.

Use print-specific CSS

Keep print rules in a dedicated @media print block or in a stylesheet loaded by the page. The @page rule controls the printable page size and margins:

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

@media print {
  body { margin: 0; }
  .application-toolbar,
  .screen-only { display: none !important; }
  .report-section { margin-block: 0 10mm; }
}

Choose one owner for page sizing. You can let Puppeteer own it with format, width, or height, or let CSS own it with @page and preferCSSPageSize: true. Mixing both is valid, but you should know which setting wins: with preferCSSPageSize enabled, the CSS page size takes priority over the PDF option’s dimensions or format. Without it, Puppeteer scales content to fit the selected paper size.

Rank #2
Brother HL-L2405W Wireless Compact Monochrome Laser Printer with Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOMES & HOME OFFICES – Engineered for consistent, premium print quality, the Brother HL-L2405W Monochrome (Black & White) Laser Printer delivers sharp, crisp prints at an affordable price. Prints one-sided documents at speeds up to 30ppm(2)
  • COMPACT, CONNECTED PRINTER – Flexible connection options make this an ideal printer for home use and at-home offices. Securely connect to multiple devices with built-in dual-band wireless (2.4GHz/5GHz) or locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Manage your printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Enjoy seamless, reliable everyday printing with the 250-sheet paper tray(4) and a manual feed slot that enables printing on envelopes and specialty pape
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer

Do not force a break for ordinary content

The browser can split paragraphs, lists, and sections over as many pages as needed. Add a forced break only at a deliberate boundary:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.chapter { break-before: page; }

.appendix { break-after: page; }

.card,
.invoice-total { break-inside: avoid; }

h2, h3 { break-after: avoid; }

break-before: page inserts a page break before the selected element in paged media. break-inside: avoid asks the engine not to split an element, but it cannot keep an element together when that element is taller than the available page area. Fragmentation rules also interact with existing breaks on neighboring elements, so inspect the rendered PDF rather than assuming every declaration will produce an identical layout.

Choose Puppeteer PDF options deliberately

Option What it controls Typical decision
format Named paper format; the documented default is Letter. Use 'A4' or another named format when your output has a known paper standard.
width / height Explicit paper dimensions. Use when a custom page size is required instead of a named format.
preferCSSPageSize Whether @page size overrides the PDF dimensions or format. Set true when the stylesheet is the source of truth.
margin Top, right, bottom, and left printable margins. Set explicitly so CSS spacing and the printable area are predictable.
printBackground Whether CSS backgrounds and background images are printed. Set true for colored panels, charts, or branded backgrounds; the default is false.
pageRanges The pages emitted from the generated document. Use when a caller needs only selected pages rather than the complete PDF.

Margins consume part of every page’s printable area. If a heading moves to the following page after you increase a margin, that is expected pagination rather than a failed break rule. Keep the paper size, margins, and CSS spacing consistent between environments.

Rank #3
Canon imageCLASS LBP6030w - Monochrome Single-Function Wireless Compact Wireless Laser Printer, 1 Year Limited Warranty, 19 PPM, White - Print Only
  • FAST PRINT SPEEDS: Print up to 19 pages per minute.
  • COMPACT DESIGN: Space-saving, compact design fits anywhere in your home, school or small office.
  • WIRELESS CONNECTIVITY: Print from almost anywhere in your workspace using your compatible mobile device.
  • PAPER CAPACITY: Up to 150 sheets.
  • SUSTAINABILITY: Uses less than 2 watts in Energy Saver mode.

Print media versus screen media

Puppeteer’s PDF method applies print CSS by default. Rules inside @media print therefore affect the PDF even when the same page looked different in a normal browser tab. If you intentionally need screen styling, call:

await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf', format: 'A4' });

For reports, invoices, and documents designed for paper, print media is usually the correct path. If a component disappears unexpectedly, inspect whether a print rule sets it to display: none, changes its position, or replaces its colors.

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

Wait for the right things before creating the PDF

Use an appropriate navigation or content-readiness condition before calling page.pdf(). In the example, setContent() waits for network idle, which is useful for a self-contained document that loads images or stylesheets. For an application page, navigate with page.goto(url, { waitUntil: 'networkidle0' }) or wait for a page-specific selector that proves the data is present.

Rank #4
Brother HL-L2460DW Wireless Compact Monochrome Laser Printer with Duplex, Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOME OFFICES & SMALL TEAMS – Engineered for consistent, premium print quality, the Brother HL-L2460DW Monochrome (Black & White) Laser Printer produces documents that are clear, crisp, and easy to review and share, all at an affordable price
  • COMPACT, CONNECTED, EXCEPTIONALLY EFFICIENT– Connect with built-in dual-band wireless (2.4GHz/5GHz), Ethernet, or to a single computer via USB interface. Prints at speeds up to 36ppm(2), plus automatic duplex printing saves time and reduces paper waste
  • BROTHER MOBILE CONNECT APP – Manage your wireless printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Tackle high-volume black & white printing with the 250-sheet capacity paper tray.(4) The manual feed slot enables printing on envelopes and specialty paper
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer

Puppeteer’s PDF guide says the PDF operation waits for fonts by default and exposes waitForFonts, which waits for document.fonts.ready. Font readiness does not prove that application data, images, or every external resource has finished loading. Wait for those resources separately when they affect pagination.

await page.goto('https://example.test/report', { waitUntil: 'networkidle0' });
await page.waitForSelector('[data-report-ready]');
await page.evaluate(() => document.fonts.ready);
await page.pdf({
  path: 'report.pdf',
  format: 'A4',
  preferCSSPageSize: true,
  printBackground: true,
  waitForFonts: true
});

A practical diagnostic sequence

  1. Confirm there is enough content to paginate. Temporarily add a long test paragraph or repeated rows. If the PDF is still one page, inspect layout constraints rather than page-break rules.
  2. Remove clipping constraints. Search ancestors of the report for fixed heights, viewport units, scroll containers, and overflow: hidden. Replace them in print CSS with ordinary height and visible overflow where appropriate.
  3. Choose one page-size authority. Either use Puppeteer’s format/width/height, or use @page with preferCSSPageSize: true.
  4. Set margins intentionally. Large margins reduce available content height and can move blocks to a later page.
  5. Check print rules. Verify that the selectors you expect are inside @media print and that no print rule hides the report.
  6. Add breaks only at stable boundaries. Put break-before: page on a section wrapper, not on an inline element or a heading that may be repeated by a component.
  7. Inspect the actual PDF. Open it at the target paper size and check long tables, images, headings, and the final page. CSS fragmentation is layout-dependent, so a declaration is not a substitute for checking the output.

Common failures and fixes

Symptom Likely cause Fix
Everything appears on one short page. A fixed-height wrapper or scroll container is clipping the document. Override the height and overflow in print CSS; allow normal block flow.
The PDF uses the wrong paper size. format and @page disagree, or CSS size is not preferred. Choose one source of truth and set preferCSSPageSize: true when CSS should win.
Colors or background graphics are missing. printBackground is false, its documented default. Set printBackground: true and verify the styles are loaded.
A section does not start on a new page. The break is applied in screen-only CSS, attached to the wrong element, or overridden by another fragmentation rule. Use break-before: page in print CSS on a block-level section wrapper and inspect neighboring break declarations.
A “keep together” card still splits. The card is taller than the available page area. Shorten or redesign the card, or allow it to fragment; break-inside: avoid is not an infinite-page guarantee.
Fonts or images change pagination between runs. Rendering began before those resources were ready. Wait for the required selector, network condition, image readiness, and document.fonts.ready before generating the PDF.
Screen layout is printed unexpectedly. The page was explicitly switched to screen media. Remove emulateMediaType('screen') or call emulateMediaType('print') before page.pdf().
The last rows are missing. Application data loaded after the PDF call, or a parent clipped overflow. Wait for a data-ready marker and remove the clipping rule; do not solve it with arbitrary delays alone.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

Launching a browser for every document adds startup work. For a service that generates many PDFs, keep a controlled browser process alive and create or close pages per job, while limiting concurrency so memory use remains predictable. Reuse the same CSS and page-size policy for all jobs to reduce layout surprises.

Use deterministic readiness signals instead of a long unconditional sleep. A selector such as [data-report-ready] communicates that your application finished rendering; network idle is helpful but may never occur on pages with persistent connections or analytics requests. Keep external assets reachable from the rendering environment, and consider embedding critical fonts or styles when reproducibility matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HP LaserJet M110w Wireless Black & White Printer, Print, Fast speeds, Easy Setup, Mobile Printing, Best-for-Small Teams
  • FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black & white documents and reports. Perfect for 1-3 people
  • WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing that fits anywhere
  • FAST PRINT SPEEDS – Up to 21 black-and-white pages per minute single-sided
  • WIRELESS WITH SELF-RESET – Helps you stay connected
  • PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more

Pagination can change when text wraps differently, fonts load at a different time, an image’s intrinsic size is missing, or margins and paper formats differ. Treat the generated PDF as the artifact to validate. Compare representative short, long, and edge-case documents whenever you change CSS.

Or skip the browser setup

If you only need a clean screenshot or PDF from a URL, ScreenshotNeo provides a GET-based screenshot API and an MCP server for AI agents. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports the result in X-Page-Verdict and X-Billed headers.

See the complete parameter reference in the ScreenshotNeo documentation. A one-call image request looks like this:

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 supports PDF output, full-page captures with lazy images loaded, CSS-selector element captures, custom CSS and JavaScript, waits for selectors or network idle, request blocking, cookies and headers, device and viewport settings, caching with a chosen TTL, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, signed links, a usage API, and an OpenAPI specification. Its MCP tools are take_screenshot, get_page_info, and capture_pdf, so Claude, Cursor, and other MCP clients can request captures without you managing Puppeteer.

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

The Free plan includes 1,000 shots per month with no card. Paid plans are Starter $5 for 3,000 shots, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; yearly billing provides two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to start.

Frequently Asked Questions

Which Puppeteer documentation version should I check for option details?

The API search material identifies the PDF documentation as version 25.12.0 and the media-emulation page as 25.11.0. Treat those numbers as documentation context, then verify the API supported by the Puppeteer version installed in your project.

Can a document combine automatic flow with selected page breaks?

Yes. Let ordinary content paginate naturally and use fragmentation rules only for boundaries that have a clear editorial reason, such as the start of a chapter or appendix.

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.

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.