The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Both Puppeteer and Playwright generate PDFs with page.pdf(), and both use print CSS media by default. For a reliable result, prepare the page, choose paper and rendering options explicitly, and inspect the PDF in the same browser version you will deploy. Flexbox content can fragment across pages, but break rules do not guarantee that every item will stay together or land on a particular page.
Generate a PDF with Puppeteer
The basic sequence is to launch a browser, create a page, navigate to the content, call page.pdf(), and close the browser. Puppeteer’s documentation puts it plainly: “For printing PDFs use Page.pdf().” Its PDF generation guide says the call waits for fonts by default; that is not a guarantee that every image, application component, or other network dependency is ready. Make your application data and required assets ready before exporting, and verify the result.
Runnable example
Install Puppeteer in a Node.js project with npm install puppeteer, then save this as print-pdf.cjs and run node print-pdf.cjs:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
margin: { top: '15mm', right: '12mm', bottom: '15mm', left: '12mm' }
});
} finally {
await browser.close();
}
})();
The navigation wait is a useful starting point, not proof that a page with long-lived requests or client-side rendering is finished. For an application page, wait for a meaningful selector or an application-level ready condition before making the PDF.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Engineered for convenience – This new Brother Monochrome Laser Printer is conveniently equipped with a flatbed scan glass for quick copying and scanning. Mobile Device Compatibility AirPrint, Google Cloud Print 2.0, Brother iPrint and Scan, Mopria, Cortado Workplace
- Optimized for efficiency – Engineered with new features, the HL L2395DW laser printer (replacement for the HLL2380DW) and has been optimized for efficiency, allowing you to print up to 36 pages per minute(1)
- Faster, high quality prints: This monochrome laser printer is built with a 250 sheet paper capacity that helps improve efficiency due to less time spent refilling trays. It also handles both letter and legal sized paper. Power Source AC 120V 50/60Hz.Machine Noise (Ready/Printing): 30dB / 50dB
- Cloud based print & scan – Print from and scan to popular Cloud services directly from the 2.7" color touchscreen, including Dropbox, Google Drive, Evernote, OneNote, and more(4)
- Wireless printing & exceptional support – This printer’s simple to connect wireless technology allows you to submit print jobs from your laptop, smartphone, desktop, and tablets(2). The "Touch to connect" printing with NFC delivers added convenience(3).
Generate a PDF with Playwright
Playwright’s Page API also provides page.pdf(). The flow is similar, so choose based on the automation library and runtime integration already used by your project, and then verify its specific options in the API reference.
Runnable example
Install Playwright with npm install playwright. Save the following as print-pdf.cjs and run it with Node.js:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.pdf({
path: 'page.pdf',
format: 'A4',
printBackground: true,
margin: { top: '15mm', right: '12mm', bottom: '15mm', left: '12mm' }
});
} finally {
await browser.close();
}
})();
These examples use A4 and explicit margins rather than relying on defaults. The documented default paper format for both libraries is Letter, which may not match the intended document. Neither the cited API documentation nor the examples establish that one library is categorically faster or more reliable; compare the needs of your project and the browser version you deploy.
Choose print or screen styling before export
PDF generation uses print media by default in both libraries. That means @media print rules apply and screen-only styles may not. This is normally appropriate for documents intended to be printed. If the PDF should instead reproduce the screen presentation, opt into screen media before calling page.pdf().
Rank #2
- FAST PRINT AND SCAN: The Brother MFC-L3710CW lets you get things done with up to 19 ppm print speed and scans up to 29 ipm in black and 22 ipm in color
- AFFORDABLE AND FLEXIBLE COLOR PRINTING: Affordably print professional quality, rich, vivid color documents with laser printer quality. The 250 sheet adjustable paper tray helps minimize refills and the manual feed slot handles varied printing needs
- 3.7” COLOR TOUCHSCREEN: Print from and scan to popular cloud apps directly from the 3.7" color touchscreen including Dropbox, Google Drive, Evernote, OneNote and more. Save time by creating custom shortcuts on the touchscreen for your most used features.
- PRINT AND CONNECT YOUR WAY: Print wirelessly from your desktop, laptop, smartphone and tablet with built-in wireless, and Wi-Fi Direct or connect locally to a single computer via USB interface.
- UNIT DIMENSIONS (WxDxH): 16.1” W x 18.7” D x 16.3” H
Puppeteer: emulate screen media
await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf', format: 'A4' });
Playwright: emulate screen media
await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'screen-styled.pdf', format: 'A4' });
Changing media affects which CSS rules apply; it does not guarantee a pixel-for-pixel screenshot or solve pagination. If the goal is a printed document, keep print media and write print-specific styles instead of switching media to hide a layout problem.
Set the PDF output deliberately
Before shipping a generated document, decide the page geometry and rendering behavior rather than accepting defaults by accident. Puppeteer’s PDF options and Playwright’s Page API document overlapping controls.
| Decision | What to choose | Why it matters |
|---|---|---|
| Paper format or dimensions | For example, A4 or Letter; use explicit width and height when needed. | Controls the page box and available content area. Both API references document Letter as the default format. |
| Orientation | Portrait or landscape. | Changes the usable width and can alter wrapping and page breaks. |
| Margins | Set top, right, bottom, and left values appropriate to the document. | Margins reduce the area available to content and affect pagination. |
| Scale | Use the documented scale option only when resizing the rendered output is intended. | Scaling can change line wrapping and the number of pages. |
| Background graphics | Enable background printing when colors or background images are part of the design. | Backgrounds are off by default in the documented options. |
| CSS page-size priority | Choose whether the CSS @page size should take priority over the API paper setting. |
CSS page sizing does not take priority by default in the documented options. |
| Headers, footers, and page ranges | Configure them only if the document needs them. | They change the exported pages and should be checked alongside margins and page count. |
Exact option names and supported values can vary with library releases. Consult the current Puppeteer PDFOptions reference or the Playwright Page API for the version in your project.
Why Flexbox breaks across PDF pages
A PDF is paged media: content must be laid out into successive page areas. CSS Paged Media describes page presentation, while CSS Fragmentation describes how content can break between those areas. Flex containers have layout-specific fragmentation behavior, so a break directive should not be assumed to work exactly as it does in ordinary block flow.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
- Create a mix using audio, music and voice tracks and recordings.
- Customize your tracks with amazing effects and helpful editing tools.
- Use tools like the Beat Maker and Midi Creator.
- Work efficiently by using Bookmarks and tools like Effect Chain, which allow you to apply multiple effects at a time
- Use one of the many other NCH multimedia applications that are integrated with MixPad.
The W3C fragmentation material identifies flex and grid as layout modes with more specific rules. The cited older Flexbox material describes possible breaks between flex items, between lines in a multi-line flex container, and inside items where the break properties allow it. The practical result depends on the layout, the content’s dimensions, the browser implementation, and the deployed version. A long flex item cannot always be kept intact when it is taller than the available page area.
Write print styles for the document
Use @media print to adjust the layout for PDF output and @page to set page-level properties such as size and margins. The W3C CSS Paged Media Level 3 document is a Working Draft dated 2023-09-14; it describes specification intent, not a guarantee that every browser implements every feature identically.
@media print {
.screen-only {
display: none !important;
}
.report-section {
break-inside: avoid;
}
.new-page {
break-before: page;
}
}
@page {
size: A4 portrait;
margin: 15mm 12mm;
}
break-before, break-after, and break-inside express where breaks are preferred or discouraged. For block text, orphans and widows can influence how lines are split. These properties communicate intent; they cannot satisfy mutually impossible constraints, such as keeping an over-height section on one page.
Inspect and adjust the actual output
- Open the generated PDF and check every page, especially flex rows near page boundaries.
- Check whether each item is too tall to fit in the remaining page area, and whether the intended break falls between items, between flex lines, or inside an item.
- Adjust item sizing, print-only spacing, or the relevant break property; if appropriate for the document, use a print-specific layout that is easier to paginate.
- Regenerate and inspect using the same browser version and settings that will run in production.
Changing Flexbox to block layout is one possible adjustment, not a universal requirement. The cited standards material does not promise identical results across browser releases, and CSS cannot guarantee a chosen page break in every situation.
Rank #4
- Save money by using PDF Fusion to view over 100 file formats without having to purchase additional software
- Merge incompatible files quickly and easily by dragging and dropping in PDF Fusion to create a new PDF documents
- Save time with PDF Fusion's editing tools to reuse the content from existing documents without starting from scratch
Choose a library and browser version based on your project
Puppeteer and Playwright both expose page.pdf() and use print media by default. The useful comparison is not a blanket winner but whether your existing application uses one library, whether its language and runtime fit your deployment, whether its documented PDF controls meet your needs, and which browser version you will run.
The Puppeteer API reference consulted for this article displays version 25.12.0. The cited Playwright Page API reference does not state a release version. The documentation cited here does not provide a fair performance benchmark or a browser-matrix comparison, so no speed or cross-browser reliability ranking is warranted.
Troubleshoot common PDF problems
- The PDF looks unlike the web page. The export uses print media by default. Add or revise
@media printrules, or explicitly emulate screen media if screen styling is the intended output. - Colors or background graphics are missing. Background printing is off by default in the documented options. Enable the background option, and use
-webkit-print-color-adjustin CSS when requesting exact color rendering. That property concerns colors, not layout or pagination. - Content is clipped or pages break in the wrong place. Verify paper size, orientation, margins, scale, and CSS
@pagepriority. Then inspect the flex items at the break and revise sizing or fragmentation rules. - Images or application content are missing. A font wait or navigation wait does not prove that every asynchronous component and external asset is ready. Wait for the relevant application state or selector before exporting.
- A section will not stay on one page.
break-inside: avoidexpresses a preference; it cannot fit content that exceeds the available page area. Shorten or resize the content, or allow it to break. - Output differs after a deployment change. Browser implementations can differ and evolve. Pin and verify the browser version used in the deployed environment, then regenerate representative PDFs after changing it.
Or skip the browser setup
If you need screenshots rather than a paginated PDF, ScreenshotNeo offers a website screenshot API and MCP server. For PDF work, Puppeteer or Playwright gives you the page and print-CSS controls discussed above. For a screenshot, a single GET request can return PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for request details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers say which outcome occurred. Its MCP server includes take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Does page.pdf() return a PDF buffer if I do not set a path?
The examples here write to a path; check the API reference for your installed library version for the return behavior and options.
Can I use these examples with a non-Node.js project?
The snippets are Node.js examples. Both libraries have language and runtime details that depend on the project; consult the relevant library documentation for your environment.
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.

