To keep a card, table row, invoice section, or heading together in a Puppeteer PDF, apply break-inside: avoid (and the legacy page-break-inside: avoid) to the block that must stay intact, then control deliberate boundaries with break-before: page or break-after: page. Export only after fonts, images, and client-rendered content are ready, and make your paper size, margins, and scale agree.
Use print CSS deliberately
page.pdf() generates a PDF with the print CSS media type. Puppeteer documents this behavior as “Generates a PDF of the page with the print CSS media type.” If your rules exist only in screen styles, they may not apply during export.
await page.goto(url, {waitUntil: 'networkidle2'});
await page.emulateMediaType('print');
Use an explicit @media print block when screen and print layouts differ. If you intentionally designed print rules as the default, emulating print still makes the choice visible and predictable.
Keep a block together
Modern property
Put break-inside: avoid on the generated block that must not split. For page-specific behavior, break-inside: avoid-page states that a page break should be avoided inside that box.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
@media print {
.invoice-section,
.keep-together {
break-inside: avoid;
break-inside: avoid-page;
}
}
Apply the rule to each repeated item (for example, every invoice section or table row wrapper), not only to a distant page container. The CSS property controls breaks inside the box itself.
Legacy alias
Older stylesheets and browser versions may still rely on page-break-inside. Keep it as a compatibility alias in new print CSS:
.keep-together {
break-inside: avoid;
page-break-inside: avoid;
}
Modern break-* names are easier to extend to columns and regions, while the alias helps existing print rules continue to work.
Tables and rows
Browsers paginate tables using their own layout rules. Wrap a logical row group or card in a block-level element and apply the avoidance rule there. If a row itself is being split, also check table structure, fixed heights, and overflow styles; an invalid or non-generated box gives the browser nothing on which to honor the rule.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Force a new page at a section boundary
Start a section on a fresh page
@media print {
.new-section {
break-before: page;
}
}
Use this on the heading or section wrapper that should begin on the next page. The older spelling, page-break-before: always, remains a compatibility option, but prefer break-before: page for new CSS.
End a section before the next page
@media print {
.section-end {
break-after: page;
}
}
Forced breaks take precedence over natural flow. Do not put a forced break on every repeated item unless that is really the intended pagination.
Complete Puppeteer implementation
The following example loads a page, selects print media, injects print rules, waits for fonts, and exports an A4 PDF. preferCSSPageSize lets the CSS @page size control the paper geometry.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('https://example.com/invoice', {
waitUntil: 'networkidle2'
});
await page.emulateMediaType('print');
await page.addStyleTag({content: `
@media print {
@page {
size: A4;
margin: 16mm;
}
.invoice-section,
.keep-together {
break-inside: avoid;
page-break-inside: avoid;
}
.new-section {
break-before: page;
}
}
`});
await page.evaluate(() => document.fonts.ready);
await page.pdf({
path: 'output.pdf',
format: 'A4',
printBackground: true,
preferCSSPageSize: true,
waitForFonts: true
});
await browser.close();
})();
Replace the URL and selectors with those in your document. If the application renders data after navigation, wait for a meaningful selector or application-ready signal as well as network activity; a quiet network does not guarantee that a framework has finished measuring and painting content.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Make paper geometry consistent
A block can appear to “ignore” break-inside: avoid when the printable area is smaller than expected. Treat these settings as one system:
- CSS paper:
@page { size: A4; margin: 16mm; }. - Puppeteer paper:
format, or explicitwidthandheight. - Margins: the CSS margins or Puppeteer margin options, avoiding accidental double margins.
- Scale: a scale below or above 1 changes how much content fits on a page.
- CSS ownership: use
preferCSSPageSize: truewhen the stylesheet should define the paper.
Choose one clear owner for dimensions. A mismatch between a CSS page size and a Puppeteer format can move a boundary even when the content has not changed.
Why an avoid rule appears not to work
The selector does not match a generated box
Inspect the element in print emulation. MDN describes break-inside as controlling breaks inside a generated box; when no generated box exists, the property is ignored. Verify the selector, display type, and the element that actually contains the content.
The content is taller than one page
Avoidance cannot create extra page area. A section taller than the printable page must be split intentionally, shortened, resized, or redesigned. For a long table, repeat a header and divide the content into logical groups rather than trying to keep the entire table intact.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
A later forced break wins
Inspect computed styles for break-before, break-after, and legacy aliases. A forced break on a descendant or adjacent section can produce a result that looks like an ignored avoidance rule.
Fixed height or clipping changes the box
Remove accidental height, max-height, and overflow: hidden declarations from the component while debugging. They can clip content or create a box whose dimensions do not match its contents.
Late fonts and images move the break
Font metrics, image dimensions, charts, and client-rendered data all affect layout. Wait for document.fonts.ready, ensure images have loaded, and export only after the application reports that its data is present. A layout measured before a web font arrives can paginate differently from the final layout.
A repeatable debugging sequence
- Call
page.emulateMediaType('print')and inspect the computed styles for the exact element that splits. - Confirm that the selector matches a block-level, generated box and that the rule is not overridden by a more specific print rule.
- Check
@pagesize, Puppeteerformator dimensions, margins, andscaletogether. - Temporarily remove fixed heights and overflow clipping.
- Wait for fonts, images, charts, and application data before calling
page.pdf(). - Search for forced
break-beforeorbreak-afterdeclarations that alter the natural break. - If the box exceeds one printable page, split it deliberately instead of relying on
avoid.
Natural flow versus forced pagination
| Goal | Rule | Trade-off |
|---|---|---|
| Keep a card or invoice section intact when it fits | break-inside: avoid |
Honors the request only when enough printable space exists. |
| Begin a chapter or major section on a new page | break-before: page |
Provides editorial control but can create extra white space. |
| End a section before the next page | break-after: page |
Useful for deliberate boundaries; overuse wastes pages. |
| Support older print stylesheets | page-break-inside: avoid |
Compatibility alias; modern code should prefer break-*. |
Performance, reliability, and repeatability
- Use
networkidle2as a navigation checkpoint, not as proof that all visual work is complete. - Give important images intrinsic dimensions or wait for their natural dimensions before export to prevent layout shifts.
- Load the same fonts in every environment; fallback fonts can change line wrapping and page count.
- Keep print CSS deterministic. Randomized content, time-dependent labels, and asynchronous charts can move breaks between runs.
- Use a stable viewport and explicit paper settings when comparing PDFs in tests.
- Log the URL, print settings, and readiness conditions for failed jobs so a pagination difference can be reproduced.
Or skip the browser setup
If you only need a clean capture or PDF endpoint rather than maintaining Puppeteer infrastructure, ScreenshotNeo accepts one GET request. It can accept cookie and consent banners before capture and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each 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. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for PDF parameters, page ranges, paper size, margins, and other options. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
FAQ
Should I use page-break-inside or break-inside?
Use modern break-inside and retain page-break-inside: avoid as a compatibility alias where older print CSS needs it.
Can Puppeteer keep any element on one page?
Only if the element fits in the printable area. Oversized content must be split or redesigned.
Why does changing a font alter page breaks?
Different font metrics change line wrapping and element heights, which changes where the browser can place breaks.
Does networkidle2 guarantee stable pagination?
No. Fonts, images, charts, and client-rendered data may still be changing after network activity quiets.
Frequently Asked Questions
Can I prevent a table row from splitting across pages?
Wrap the row’s logical content in a generated block and apply break-inside: avoid plus the legacy alias, then verify that the row fits within the printable page.
What is the difference between format: 'A4' and preferCSSPageSize?
The format supplies Puppeteer’s paper size; preferCSSPageSize: true gives precedence to the CSS @page size. Keep the chosen geometry consistent.
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.

