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.

Set the PDF’s geometry either in CSS with @page or in your browser automation call with explicit width and height. If CSS should control the result in Playwright or Puppeteer, add preferCSSPageSize: true. Use physical units such as mm, cm, or in, define margins explicitly, and keep one place responsible for page size.

Choose who controls the page width

There are two reliable models for HTML-to-PDF exports:

Model Set width in Best when Important behavior
CSS-owned geometry @page { size: ... } The same print layout must work in browser printing and automated exports Set preferCSSPageSize: true in Playwright or Puppeteer so the CSS page size takes priority
API-owned geometry The PDF call’s width and height A service chooses paper size per request Those dimensions control the export; conflicting CSS can be scaled to fit

Do not casually configure both models with different values. Decide whether the stylesheet or the export request is authoritative, then make the other layer agree or leave it unset.

Set width with CSS @page

The @page at-rule controls printed page dimensions, orientation, and margins. A4 portrait with a 12 mm margin on every side looks like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
  • 1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing
@page {
  size: 210mm 297mm;
  margin: 12mm;
}

@media print {
  .screen-only { display: none; }
  .export-content { width: auto; }
}

The first value is the page width and the second is the page height. Swap them for landscape output. Physical units are usually easier to reason about than pixels when the PDF represents paper.

Why explicit margins matter

The declared page width is not the width available to your content. Usable width equals page width minus the left and right margins. Explicit margins make that calculation stable and prevent a browser default from silently narrowing the document.

Keep export-only rules in print media

Automated PDF generation uses the print CSS media type by default. Put visibility, layout, and sizing changes that are only for the PDF in @media print. This prevents an export workaround from changing the normal screen page.

Avoid viewport units in @page

Do not use vw, vh, vmin, or vmax for the @page size. Their handling in this context remains under discussion, so physical units are safer for repeatable paper geometry.

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

Playwright: export an A4-width PDF

Playwright’s page.pdf() accepts px, in, cm, and mm values. It renders with print media and can give CSS page geometry priority:

Rank #2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
  • HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America. Each ream is wrapped in a polyurethane coated paper wrapper to protect the cut sheets from moisture damage
  • Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
  • HP Copy&Print20 20 pounds printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design)
  • All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment; 100% satisfaction guaranteed; ColorLok technology provides more vivid colors, bolder blacks and faster drying
  • Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office; HP Copy&Print20 print and copy paper prevents yellowing over time to ensure a long-lasting appearance for added archival quality
import { chromium } from 'playwright';

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

await page.pdf({
  path: 'export.pdf',
  width: '210mm',
  height: '297mm',
  margin: {
    top: '12mm',
    right: '12mm',
    bottom: '12mm',
    left: '12mm'
  },
  preferCSSPageSize: true,
  printBackground: true
});

await browser.close();

When preferCSSPageSize is true, the @page size wins over the API’s width, height, or format. This is useful when your CSS is the single source of truth. If you want the request to own geometry instead, remove the CSS size or set this option to false and use the API dimensions consistently.

Use screen styles deliberately

Because PDF generation uses print media, screen-only styles are not selected automatically. If the PDF must reproduce the screen stylesheet, switch media before calling pdf():

await page.emulateMediaType('screen');
await page.pdf({
  path: 'screen-layout.pdf',
  width: '210mm',
  height: '297mm',
  printBackground: true
});

Only do this when screen rendering is actually the intended output; print rules are normally better for paginated documents.

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

Puppeteer: the equivalent configuration

Puppeteer exposes the same core controls, including width, height, format, margins, scale, printBackground, and preferCSSPageSize:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com/article', { waitUntil: 'networkidle0' });

await page.pdf({
  path: 'export.pdf',
  width: '210mm',
  height: '297mm',
  margin: {
    top: '12mm',
    right: '12mm',
    bottom: '12mm',
    left: '12mm'
  },
  preferCSSPageSize: true,
  printBackground: true
});

await browser.close();

Puppeteer’s documented default for preferCSSPageSize is false. With the default, a CSS page size can be scaled to fit the selected paper size. Set it to true whenever your @page declaration must remain authoritative.

Rank #3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
  • 3 ream case (1,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Width, margins, and content that does not fit

Wide tables and images

Changing page width can expose overflow that was hidden on screen. Check wide tables, code blocks, charts, and images after every geometry change. Give images a print-safe maximum width and decide whether a table may wrap, shrink, or continue on another page.

Fixed-position elements

Headers, footers, chat-like controls, and other fixed-position elements can overlap content or repeat unexpectedly in print layout. Hide screen-only controls in @media print and verify every page rather than inspecting only the first.

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

Page breaks

A narrower content box creates more line wraps and therefore more page breaks. A wider box can move a heading and its following content onto a different page. Treat page-break behavior as a layout consequence of width, not as a separate rendering bug.

Diagnose a PDF that is too narrow or scaled

  1. Check the owner. Find every @page declaration and every width, height, or format option in the export call.
  2. Make the values agree. Use the same physical dimensions and explicit margins, or remove the non-authoritative setting.
  3. Set precedence. Add preferCSSPageSize: true when CSS owns the geometry.
  4. Inspect print media. Confirm that @media print is not setting a narrower wrapper, fixed width, or unexpected display rule.
  5. Measure the content box. Subtract both margins from the page width and compare that result with the widest element.
  6. Render all pages. Look for overflow, clipped backgrounds, collisions, and changed breaks at the new width.

Common failures and fixes

“My @page size is ignored”

In Playwright or Puppeteer, the API paper settings may be taking precedence. Set preferCSSPageSize: true, or remove the CSS size and let the API own the dimensions.

“The PDF looks like the screen, not the print layout”

That is usually a media mismatch. PDF generation selects print media. Move export rules into @media print, or explicitly call page.emulateMediaType('screen') when screen CSS is the requirement.

Rank #4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
  • 5 ream case (2,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

“The page is the right size but the content is tiny”

The content may be wider than the usable area, causing it to be scaled to fit. Reduce the widest element, correct its wrapper width, or increase the page width. Also check whether an API paper size is forcing a scale over your CSS geometry.

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

“Background colors disappeared”

Enable printBackground: true in the PDF call. This is independent of page width but commonly appears during print-layout changes.

“Different pages break differently after a width change”

That is expected: width changes line wrapping and element heights. Recheck headings, tables, images, and fixed elements across the complete document.

Performance and reliability considerations

Waiting for network idle helps ensure that late-loading resources have arrived before capture, but it does not replace layout validation. Use a deterministic page size, explicit margins, and a stable print stylesheet. If content depends on JavaScript, wait for the relevant selector or application state before calling pdf(). Keep the browser and its page-printing behavior consistent between development and production so small engine differences do not change pagination unexpectedly.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a PDF capture API as well as screenshots. Its documentation covers paper size, margins, landscape mode, and page ranges, so you can request PDF geometry without maintaining Playwright or Puppeteer yourself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HP Printer Paper | 8.5 x 11 Paper | Office 20 lb | 3 Ream Case - 1500 Sheets | 92 Bright | Made in USA - FSC Certified | 112090C, White
  • Made in USA: HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America.
  • Optimized for HP technology: All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment.
  • Perfect everyday office paper: Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office. Perfect for everyday black and white printing.
  • Certified sustainable: HP Office20 20lb printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design).
  • ColorLok technology printing paper: ColorLok technology provides more vivid colors, bolder blacks and faster drying.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

For a PDF request, use ScreenshotNeo’s PDF options for the target paper size, margins, orientation, and page range. The service can also wait for a selector, delay, or network idle; run custom JavaScript; click an element; hide selectors; block unwanted requests or resource types; and set headers, cookies, user agents, time zone, or geolocation. Full-page capture loads lazy images, and an element can be selected by CSS selector.

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 removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing result. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for AI clients, plus caching with a chosen TTL, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. One thousand shots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can I use pixels instead of millimetres?

Yes. Playwright and Puppeteer document px, in, cm, and mm. Pixels are useful when matching a pixel-based workflow; physical units are easier to predict for paper output.

Should I set both format and width/height?

Choose one geometry model. Use explicit width and height, or let a named format define paper size; avoid conflicting values unless you have deliberately selected which setting takes precedence.

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

Does changing width alter the HTML page in the browser?

No. @page and @media print affect print rendering. Screen output changes only if you separately modify the screen stylesheet or emulate screen media during export.

Quick Recap

Bestseller No. 1
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use; Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$6.97
Bestseller No. 2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
$6.97
Bestseller No. 3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$23.99
Bestseller No. 4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$34.85

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.