October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Set Margins When Generating PDFs with Puppeteer

Set Puppeteer PDF margins with a four-edge margin object, then choose whether page size comes from format options or CSS @page.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass a margin object to page.pdf(), with separate values for top, right, bottom and left. Use strings with explicit units, such as '20mm', when you need predictable physical measurements. Puppeteer documents no margins as the default when margin is undefined.

Set the four PDF margins in Puppeteer

Choose the paper size and add the margin object to the same page.pdf() call:

As an Amazon Associate I earn from qualifying purchases.

await page.pdf({
  format: 'A4',
  margin: {
    top: '20mm',
    right: '15mm',
    bottom: '20mm',
    left: '15mm',
  },
  path: 'output.pdf',
});

This is an illustrative configuration. The margin object accepts optional edge values, each documented as a string or number. Explicit-unit strings make the intended physical size clear. The official type reference does not specify a unit-conversion table. Puppeteer PDFMargin interface

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.

Use equal margins

For the same margin on every edge, provide the same value four times:

#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
await page.pdf({
  format: 'Letter',
  margin: {
    top: '0.5in',
    right: '0.5in',
    bottom: '0.5in',
    left: '0.5in',
  },
  path: 'output.pdf',
});

The API shape uses named edges rather than a single shorthand value, so specify all four when you want uniform margins. Puppeteer PDFOptions interface

Leave margins unset

If you omit margin, its documented value is undefined, which Puppeteer describes as no margins set. Do not assume a browser-style default margin will be added automatically. Puppeteer PDFOptions interface

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

Choose page size separately from margins

Margins control the space at the edges; they do not select the paper format. Puppeteer defaults to Letter. If you set format, it takes precedence over width and height. The documented dimensions include Letter at 8.5 × 11 inches and A4 at 210 × 297 millimeters. Puppeteer PaperFormat type Puppeteer PDFOptions interface

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Set Effect
Choose a standard paper size format: 'Letter' or format: 'A4' Uses the selected format; if format is supplied, it takes precedence over width and height.
Specify dimensions directly width and height Sets dimensions when a higher-priority format is not supplied.
Let CSS choose page size Set preferCSSPageSize: true and define size in CSS @page CSS page size takes priority over width, height or format.

With preferCSSPageSize omitted or false, a CSS @page size is scaled to fit the PDF option’s paper size. This option documents precedence for page size; it does not establish a general precedence rule for conflicts between API margins and CSS @page margins. If both define margins, check the result on the Puppeteer and Chrome versions your application deploys. Puppeteer PDFOptions interface

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

Account for print CSS

page.pdf() renders using print CSS media. A print stylesheet can therefore change the page layout compared with what you see in a normal browser window. If you specifically need screen-media styling, call page.emulateMediaType('screen') before generating the PDF:

await page.emulateMediaType('screen');
await page.pdf({
  format: 'A4',
  margin: {
    top: '20mm',
    right: '15mm',
    bottom: '20mm',
    left: '15mm',
  },
  path: 'output.pdf',
});

Use screen media only when that is the intended output; otherwise, review the page’s print styles when the PDF differs from the screen view. Puppeteer Page.pdf() method

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

Check the result and troubleshoot layout problems

  • The PDF has unexpected whitespace: confirm that every margin edge has the value you intended. An omitted margin object does not set margins. Also check the page’s print styles.
  • The PDF uses the wrong paper dimensions: check whether format is set, because it takes priority over width and height. If CSS should determine the size, set preferCSSPageSize: true and define the size in @page.
  • The output differs from the browser view: PDF generation uses print media by default. Inspect print-specific CSS, or explicitly emulate screen media before calling page.pdf() if screen styling is required.
  • CSS and API margins conflict: the cited API references do not establish universal precedence for that interaction. Test the exact stylesheet, Puppeteer version and Chrome version used in deployment rather than relying on an assumed rule.
  • The physical margin is unclear: use a string with an explicit unit, such as '0.5in' or '15mm', rather than relying on an undocumented conversion assumption.
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 screenshot or PDF from a URL without setting up Puppeteer, ScreenshotNeo offers a single-request API. Its PDF options include paper size and margins. See the ScreenshotNeo documentation for request options and authentication.

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

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
$21.96
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
$29.14
Bestseller No. 5
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$53.19
Best Value
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
  • 8 ream case (4,000 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
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 shots per month with no card required; paid plans start at $5 for 3,000 shots.

Create a free ScreenshotNeo account.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.