Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

How to Save a Webpage as a PDF from the Command Line

Run Chrome Headless to save a URL as output.pdf, or use Playwright when your PDF workflow needs explicit layout settings and page-specific waits.

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.

For a quick webpage-to-PDF capture, run Chrome headless with --print-to-pdf:

chrome --headless --print-to-pdf "https://example.com/"

Chrome saves output.pdf in the current working directory. Add --no-pdf-header-footer to omit the printed date, URL, and page-number header and footer. For scripted jobs that need paper size, margins, page ranges, or custom waits, use Playwright instead.

As an Amazon Associate I earn from qualifying purchases.

Save a URL as a PDF with Chrome Headless

Chrome’s documented headless command-line option prints the target page to a PDF named output.pdf in the current working directory. The reference was last updated October 21, 2024. See the Chrome Headless command-line reference for current details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless --print-to-pdf "https://example.com/"

To suppress the printed header and footer, including the URL, date/time, and page numbers, use:

#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C
chrome --headless --print-to-pdf --no-pdf-header-footer "https://example.com/"

The command assumes Chrome is installed and its executable is available as chrome in your shell. Binary names and installation steps vary by operating system and package. If the command is not found, locate the installed browser executable or use the Playwright workflow below.

Choose the output location

Chrome writes output.pdf to the current directory. Run the command from the directory where you want the file, then confirm that the PDF was created. The documented command does not show a custom output-path option; use Playwright with a path setting when you need to name a destination explicitly.

Set a capture time

Chrome’s --timeout=<milliseconds> sets the maximum wait before capture, even if the page is still loading. For example, the documentation uses --timeout=5000 as an example of waiting up to five seconds:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless --print-to-pdf --timeout=5000 "https://example.com/"

This is an example value, not a universal recommendation. A virtual-time budget can fast-forward time-dependent page scripts; Chrome documents --virtual-time-budget=42000 as an example:

Rank #2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
  • Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
  • Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
  • Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
  • Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
  • From Sandisk, a brand professional photographers trust to take on assignments.
chrome --headless --print-to-pdf --virtual-time-budget=42000 "https://example.com/"

These controls affect capture timing; they do not guarantee that every network request, image, or other page element has finished loading.

Use Playwright for repeatable PDF jobs

Choose Playwright when PDF generation belongs in a script or when you need direct control over paper format, margins, orientation, page ranges, print backgrounds, or CSS page sizing. Its page.pdf() API uses print CSS by default. If you want the page rendered with screen media before printing, emulate screen media first. Consult the Playwright Page API reference for options and signatures.

Minimal Node.js example

Install Playwright in your project and install a supported browser as described in its browser documentation. Then save this as a JavaScript file and run it with Node.js:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com/', { waitUntil: 'load' });
    await page.pdf({
      path: 'page.pdf',
      format: 'A4',
      printBackground: true,
      margin: {
        top: '12mm',
        right: '12mm',
        bottom: '12mm',
        left: '12mm'
      }
    });
  } finally {
    await browser.close();
  }
})();

The example saves page.pdf in the working directory, uses A4 paper, prints background graphics, and sets 12 mm margins. Change the URL, path, and settings to suit the job. The API also supports orientation, page ranges, and preferCSSPageSize. By default, Playwright applies print CSS and may modify colors for printing; CSS -webkit-print-color-adjust can be used when exact colors are needed.

Rank #3
SSK Portable SSD 500GB External Solid State Hard Drive USB C Up to 1050MB/s
  • Capacity Display Variance: 500GB external ssd often appears as around 465GB on Windows. MacOS can show full 500 GB capacity. This is binary calculation difference and doesn’t affect SSD hard drive actual physical storage
  • 1050 MB/s Speed: Instantly access to your files with blazing-fast 10Gbps external SSD read up to 1050MB/s and write up to 1000MB/s. LED Light indicates USB SSD instant activity
  • Data Security: Solid state drives S.M.A.R.T. health diagnostics​ and adaptive TRIM optimizing data block management ensures consistent write speeds and extends the longevity of the portable SSD
  • USB-C & USB-A Cable: Both cables featuring rapid USB 3.2 Gen2, this USB SSD effortlessly bridges devices, enabling seamless cross-platform file transfers and backup between computers, smartphones, tablets and iPhone
  • Always Fast: No slowdowns for large file transfers. With SLC caching (25% of current available capacity allocated as high-speed cache), this external SSD delivers steady 10Gbps for transfers within the cache capacity

Wait for page-specific content

A successful navigation does not necessarily mean a site’s dynamic content is ready for printing. When a page has a known element that appears after its content loads, wait for that element before calling page.pdf():

await page.goto('https://example.com/', { waitUntil: 'load' });
await page.locator('#main-content').waitFor({ state: 'visible' });
await page.pdf({ path: 'page.pdf', format: 'A4' });

Replace #main-content with a selector that exists on the target page. A fixed delay can be used when there is no reliable selector, but it may waste time or still be too short; verify the resulting PDF.

Check browser consistency

Playwright distinguishes its bundled Chromium/headless shell from branded Chrome or Edge, and headless behavior can differ. If output must match a particular deployment environment, identify the browser channel in your automation and inspect the PDF there. The Playwright browser documentation explains browser options.

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

Alternative: wkhtmltopdf

wkhtmltopdf is a standalone command-line utility for converting a URL or HTML document to PDF. Its project describes it as a headless utility using the Qt WebKit rendering engine. That is a different rendering engine from current Chrome, so do not assume the layout, CSS, or dynamic-page behavior will match. Test it against the pages you need to convert before relying on it.

Rank #4
Sale
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
  • NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
  • IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
  • POCKET-SIZED – fits easily in pockets and small bags.
  • SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
  • 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.

Make the PDF match the page you need

Browser-generated PDFs use print layout rules, so a PDF is not necessarily a pixel-identical copy of what appears in the browser viewport. Print styles may change colors, hide elements, or rearrange content. Choose the tool and settings based on whether you need a document-style printout or a visual capture.

  • Headers and footers: Chrome’s --no-pdf-header-footer removes the printed header and footer. In Playwright, configure the PDF options appropriate to the desired output.
  • Paper size and margins: Use Playwright’s paper-format and margin options for explicit control.
  • Backgrounds and colors: Enable print backgrounds when needed; print CSS and browser color adjustment can still affect appearance.
  • Page ranges and orientation: Use Playwright’s PDF options when you need selected pages or landscape output.
  • Lazy or dynamic content: Wait for a site-specific condition or adjust capture timing, then inspect the saved file.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

The shell says the Chrome command cannot be found

The executable may not be installed, may not be on the shell’s PATH, or may use a different name on your operating system. Check the browser installation and invoke its actual executable, or use Playwright with a browser installed for the project.

The PDF is missing images or page content

The page may load content after initial navigation, use lazy loading, or still be waiting on network activity. Increase Chrome’s capture wait where appropriate, use a virtual-time budget for time-dependent scripts, or wait for a meaningful page selector in Playwright. Neither a timeout nor virtual time guarantees completion of all site activity.

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

The PDF layout differs from the browser

PDF generation follows print layout behavior, including print CSS. Check the page’s print styles, Playwright’s print settings, and the browser used to generate the file. If the task requires a close match to screen rendering, Playwright can emulate screen media before printing, but the final PDF should still be checked in the environment that will produce it.

Best Value
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

The command finishes but the output is not where expected

Chrome’s documented command writes output.pdf to the current working directory. Check the directory from which the command ran. For a chosen filename or destination path, use Playwright’s PDF path option.

A page requires login or interaction

A single command may not reproduce content that depends on an authenticated session, a user action, or site-specific loading. The appropriate handling depends on the website. Do not assume a general URL-to-PDF command can bypass access requirements or perform arbitrary interactions.

Or skip the browser setup

ScreenshotNeo can return a PDF from one GET request, without installing or managing a browser in your script. Its API also accepts options for PDF paper size, margins, landscape orientation, and page ranges. See the ScreenshotNeo documentation.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf

For a target URL with shell-special characters or query parameters, quote or URL-encode the URL appropriately. ScreenshotNeo accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

The free plan includes 1,000 shots per month with no card required; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Can I save a webpage as a PDF without opening a browser window?

Yes. Chrome’s headless mode and Playwright can generate PDFs from the command line or a script without a visible browser window.

Does a webpage PDF preserve the exact screen appearance?

Not necessarily. Browser PDF generation uses print layout rules, which can differ from the screen layout.

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

Quick Recap

Bestseller No. 2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model)
From Sandisk, a brand professional photographers trust to take on assignments.
$188.90
SaleBestseller No. 4
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model
IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.; POCKET-SIZED – fits easily in pockets and small bags.
$249.17
SaleBestseller No. 5
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99

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.