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 Saving PDFs with Puppeteer

Set all four sides with the margin option in Puppeteer's page.pdf(). Learn how margins interact with paper size, CSS @page, and print media.

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.

Set the margin option in the options object passed to page.pdf(). Give each side its own unit-bearing value for predictable page padding:

await page.pdf({
  path: 'output.pdf',
  margin: {
    top: '1in',
    right: '0.75in',
    bottom: '1in',
    left: '0.75in',
  },
});

Set each PDF margin independently

Puppeteer’s PDFOptions accepts a margin object with top, right, bottom, and left values. Each side is optional in the API type, but specifying all four avoids relying on implicit values when you need a consistent layout.

As an Amazon Associate I earn from qualifying purchases.

Use strings with explicit units, such as '1in' or '12mm'. The API reference describes the accepted values as strings or numbers, but does not specify numeric-value units in the cited material, so unit-bearing strings make the intended measurement clear.

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

Example with four sides

await page.pdf({
  path: 'output.pdf',
  margin: {
    top: '1in',
    right: '0.75in',
    bottom: '1in',
    left: '0.75in',
  },
});

The margin option defaults to undefined, which means no margins are set. Do not omit it if the PDF needs deliberate padding.

Choose paper size and CSS page dimensions

The documented default paper format is Letter. If the document is intended for another paper size, such as A4, set a format in the same page.pdf() options object. Paper size and margins jointly determine the available content area.

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

If your stylesheet defines page dimensions with CSS @page, consider preferCSSPageSize. It defaults to false; setting it to true gives the CSS page size priority over the PDF options width, height, or format. Decide which source should control the paper dimensions rather than assuming both will apply independently.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Choose print or screen styles before generating the PDF

page.pdf() uses the print media type by default. If the PDF should use your screen styles instead, set the media type before calling page.pdf():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.emulateMediaType('screen');
await page.pdf({
  path: 'output.pdf',
  margin: {
    top: '1in',
    right: '0.75in',
    bottom: '1in',
    left: '0.75in',
  },
});

Media type affects which CSS rules render; paper format, CSS page dimensions, and margins affect the PDF’s page layout. Check the CSS and PDF options together when the result differs from the browser view.

Troubleshoot unexpected margins or page layout

  • No visible padding: confirm that margin is present in the options passed directly to page.pdf(). Leaving it out means Puppeteer sets no margins.
  • One edge is wrong: inspect the matching side key—top, right, bottom, or left—and use an explicit unit-bearing string.
  • Wrong paper dimensions: remember the documented default is Letter. Set format to the intended size, or use preferCSSPageSize: true when CSS @page dimensions should take priority.
  • PDF styling differs from the page in a browser: PDF generation uses print media by default. Call page.emulateMediaType('screen') first only when screen styles are desired.

The Puppeteer API references establish the option names and defaults, but do not guarantee a particular rendered result across browser or Puppeteer versions. Check the documentation matching your installed Puppeteer version; the cited API reference pages identify PDFOptions v25.12.0 and PDFMargin v25.9.0 in their search results.

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

Or skip the browser setup

If you need a screenshot or PDF of a web page rather than control of a Puppeteer workflow, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its PDF options include paper size, margins, landscape orientation, and page ranges.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
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 API documentation for request options. ScreenshotNeo accepts cookie or consent banners and removes more than 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 report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

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

Sign up for 1,000 free screenshots a month with no card.

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 *

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.