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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use Python Playwright’s page.pdf() method and give the PDF a custom paper height large enough for the page content. Playwright does not document an automatic option that measures an arbitrary page and fits all of it onto one PDF sheet. A custom-height sheet can keep the output to one page, but you must check the generated PDF for clipping and text that has become too small to read.

What “single-page PDF” means in Playwright

A PDF page is a sheet of paper with defined dimensions. To put a long web page on one sheet, you can create a custom-height sheet that is tall enough to contain the rendered content. That is different from fitting the same content onto standard Letter or A4 paper: a standard-size sheet may require pagination, or shrinking the content until it fits.

The Playwright Python API documents paper dimensions, scale, CSS page sizing and page ranges, but not a dedicated automatic “fit the entire document onto one page” option. The height needed depends on the page and its print styles, so no single dimension is guaranteed to work for every URL. See the Playwright Python Page API reference.

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

Generate a PDF on a custom-height sheet

This synchronous example opens a URL in Chromium and saves a PDF using an illustrative 8.5-by-20-inch sheet:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")

    page.pdf(
        path="page.pdf",
        width="8.5in",
        height="20in",
        print_background=True,
        margin={"top": "0", "right": "0", "bottom": "0", "left": "0"},
    )
    browser.close()

The 20-inch height is an example, not a recommended universal value or a guarantee that a page will fit. Choose dimensions after considering the actual rendered content, then open the resulting PDF and inspect it. The example follows the documented API shape; it has not been tested against every site or layout.

Install and launch Chromium

Install the Python package and its browser binary before running the script:

pip install playwright
playwright install chromium

The script uses the synchronous API and launches Chromium. If you are working in an environment where a browser is already installed or managed separately, follow that environment’s Playwright setup rather than assuming these commands are appropriate there.

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.

Choose the sheet dimensions deliberately

width and height accept px, in, cm or mm. A numeric value without a unit is interpreted as pixels. For a custom tall sheet, set width and height explicitly; do not rely on the illustrative dimensions above for a different page.

The API’s standard format option selects a named paper size and takes priority over width and height. Its default is Letter. If your goal is a custom tall sheet, use explicit dimensions and avoid also setting a standard format that would override them.

Inspect the output, not just the call

After generating page.pdf, check that content at the bottom is present, that important sections are not clipped, and that text remains legible. If the document spans several pages, the chosen sheet height or print layout did not contain it as intended. Increasing height may help; reducing scale can also help, but it makes all content smaller.

Control the PDF’s layout and appearance

page.pdf() renders using print CSS media by default. That means the PDF reflects print-specific rules when the page defines them, which can differ from what you see in a normal browser window. Print backgrounds are off by default, margins default to none, and PDF colors are adjusted for printing unless CSS requests exact colors.

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

Print CSS or screen CSS

For the normal print-oriented result, leave the page in print media. If you need the layout used by screen styles instead, call page.emulate_media(media="screen") before page.pdf():

page.emulate_media(media="screen")
page.pdf(path="page.pdf", width="8.5in", height="20in")

Screen styling does not itself make the content fit on one sheet. It changes which CSS media rules apply; the PDF dimensions and resulting layout still need to be checked.

CSS-controlled page size

You can define page dimensions in the document’s CSS with an @page rule and pass prefer_css_page_size=True. This option gives CSS page size priority over the API’s width, height or format settings. If it is false, the default, content is scaled to fit the paper size.

page.pdf(
    path="page.pdf",
    prefer_css_page_size=True,
    print_background=True,
)

Use this approach when the page’s own print stylesheet is responsible for sizing the sheet. If you instead want to control dimensions from Python, set width and height directly. Avoid conflicting CSS and API sizing assumptions: decide which one should control the page and inspect the result.

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

Margins, backgrounds and scale

  • Margins: set the four values explicitly if you need predictable whitespace. The API default is no margins. Zero margins can maximize usable sheet area, but may not suit every layout or printer workflow.
  • Backgrounds: use print_background=True to include background graphics; the default is false.
  • Scale: the default is 1; the documented range is 0.1 to 2. A value below 1 can make more content fit but also reduce readability. It is not a substitute for measuring the page or selecting appropriate sheet dimensions.
  • Colors: PDF output modifies colors for printing by default. The API reference identifies the CSS property -webkit-print-color-adjust for requesting exact colors.

Save to disk, return bytes, or select pages

Pass path to save the PDF to a file. Without a path, page.pdf() returns PDF bytes, which you can handle in your application instead of writing directly to disk. page_ranges selects ranges from the generated document; it does not measure the content or automatically force it onto a single sheet.

pdf_bytes = page.pdf(
    width="8.5in",
    height="20in",
    print_background=True,
)

with open("page.pdf", "wb") as f:
    f.write(pdf_bytes)

Use page ranges when you already know which generated PDF pages you want to retain. If the objective is one tall sheet, configure the paper size and layout first rather than treating a page range as a fit option.

Why a PDF may still have multiple pages

  • The sheet is not tall enough: increase the custom height or adjust the page’s print layout, then generate and inspect another PDF.
  • A standard format is taking precedence: if format is set, it takes priority over width and height. Remove the standard format when the aim is custom dimensions.
  • CSS page sizing is overriding your choice: when prefer_css_page_size=True, CSS @page size takes priority. Change the CSS size or use API dimensions as the controlling method.
  • Print media changes the page: page.pdf() uses print media by default. Check the site’s print styles; if screen styling is specifically required, emulate screen media before PDF generation.
  • The page’s content is dynamic or incomplete: the PDF reflects the page state at the time of capture. Ensure the page has reached the state you need before calling page.pdf(); a custom height cannot restore content that never appeared.

Trade-offs: one tall sheet or standard pages?

Choice What it does Best suited to Trade-off
Custom tall sheet Uses explicit width and height, or CSS page sizing, to create a sheet intended to contain the content. A continuous page capture or a document that will be viewed digitally as one long sheet. You need to choose a suitable height and verify that content is not clipped. It is not a conventional paper document.
Standard paper format Uses a format such as the default Letter size, typically with the document divided across pages as needed. Printing, sharing or reading a conventional multi-page document. It may not be a single page; shrinking to force content onto one sheet can make text difficult to read.

For a long document intended for people to read or print, normal pagination is often more usable than a single unusually tall sheet. If a single sheet is a firm requirement, treat height and legibility as separate checks: a PDF can technically fit while still being impractical to read.

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 one-request website capture, ScreenshotNeo offers a screenshot API that can return an image or PDF. This is an alternative when you want a hosted capture rather than running the Python Playwright browser yourself; it is not a Python page.pdf() implementation or an automatic guarantee that arbitrary HTML will fit on one tall sheet.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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/consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each of those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Frequently asked questions

Can Playwright automatically detect the full page height for a one-page PDF?

The documented PDF options cover paper sizing and scaling, but do not provide a dedicated automatic full-document-to-one-page fit setting. Determine a suitable size for the rendered document and inspect the result.

Does page_ranges make a PDF one page?

No. It selects pages from the generated document; it does not change the layout or fit content to a single sheet.

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

Does a custom-height PDF behave like a normal printed document?

No. It is one large sheet rather than a conventional sequence of paper-sized pages. Use standard pagination when that format is more useful to the reader or printer.

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.