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

With Chrome or Chromium installed, the quickest way to convert a web page to PDF in Bash is chrome --headless --print-to-pdf=page.pdf https://example.com. It saves a PDF without opening a visible browser window. For modern, JavaScript-heavy pages, headless Chrome is a sensible starting point; WeasyPrint and wkhtmltopdf are alternatives when their styling or print-layout controls better fit your task.

Convert a URL to PDF with Chrome or Chromium

Run the command from Bash, replacing the URL and filename with your own:

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

Chrome’s headless printing command creates a PDF in the current working directory. If you omit the filename, its documented default output is output.pdf. The command-line documentation and options are described in Chrome’s headless Chrome documentation.

Some Linux distributions expose the browser as chromium or chromium-browser instead of chrome. Use the executable name installed on your system; the flags below are Chrome’s documented headless-printing options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Choose the output path

To save the file in another directory, give Chrome a path as the value of --print-to-pdf:

chrome --headless --print-to-pdf="$HOME/Downloads/page.pdf" https://example.com

The target directory must exist and be writable by the user running the command. If you provide a relative path, it is interpreted from the current working directory.

Remove the printed date, URL, and page number

Chrome adds print header and footer details by default. Suppress them with --no-pdf-header-footer:

chrome --headless --print-to-pdf=page.pdf --no-pdf-header-footer https://example.com

This removes the browser’s printed date/time, URL, and page number. Older Chrome installations may use the historical flag spelling --print-to-pdf-no-header; if the current flag is rejected, check the documentation for your installed version.

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.

Give slow pages time to render

For pages that need a short wait before capture, Chrome documents --timeout, with --timeout=5000 specifying a maximum capture wait of five seconds:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
chrome --headless --timeout=5000 --print-to-pdf=page.pdf https://example.com

For pages that rely on JavaScript timers, --virtual-time-budget advances those timers in virtual time. For example:

chrome --headless --virtual-time-budget=42000 --print-to-pdf=page.pdf https://example.com

These are timing controls, not guarantees that a page is ready. A site may still be waiting for network requests, authentication, an API response, or application-specific conditions. Inspect the PDF when completeness matters.

Choose a renderer for the page and output you need

Renderer Good fit Important qualification
Chrome or Chromium Pages that depend on modern browser behavior or client-side JavaScript. Wait settings do not guarantee that every page has finished loading. Verify the generated PDF. Chrome documentation.
WeasyPrint A direct HTML/CSS-to-PDF command-line workflow, including applying a stylesheet. Some CSS properties may be unsupported, and its documentation warns about untrusted HTML or CSS. WeasyPrint documentation.
wkhtmltopdf Workflows that need documented page-size, margin, orientation, print-media, header/footer, or JavaScript controls. The documented manual is for version 0.12.6 with patched Qt. The project identifies 0.12.6 as its stable series, released June 11, 2020, and warns against processing untrusted HTML/JavaScript. Check your package’s build and behavior. Project site and downloads.

Use WeasyPrint from Bash

WeasyPrint accepts a page URL and output path directly:

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.
weasyprint https://example.com page.pdf

To add an inline stylesheet from Bash, use process substitution:

weasyprint https://example.com page.pdf 
  -s <(echo 'body { font-family: serif !important }')

This is useful when you want a stylesheet adjustment without creating a separate CSS file. WeasyPrint can report unsupported CSS properties on standard error, so review its output and inspect the PDF if layout fidelity matters. It is an HTML/CSS renderer, not a promise of pixel-identical output to Chrome. Its documentation also cautions that untrusted HTML or CSS can create security problems.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use wkhtmltopdf from Bash

The basic conversion is:

wkhtmltopdf https://example.com page.pdf

The upstream manual documents controls for paper size, margins, orientation, JavaScript enablement and delay, print-media selection, headers and footers, and multiple page objects. Consult the manual corresponding to your installed build before scripting around an option: the upstream manual is explicitly for wkhtmltopdf 0.12.6 with patched Qt, and distribution packages may differ.

wkhtmltopdf is a legacy choice rather than a default for every new workflow. Its official project page dates stable 0.12.6 to June 11, 2020, and warns not to process untrusted HTML or JavaScript because doing so can compromise the server. WeasyPrint likewise flags untrusted HTML/CSS as a security concern. For either tool, only process content you trust or isolate the conversion environment appropriately.

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

Automate conversion in a Bash script

A simple script can take a URL and destination as arguments. This example uses Chrome and fails early if the executable or arguments are missing:

#!/usr/bin/env bash
set -euo pipefail

if [[ $# -ne 2 ]]; then
  echo "Usage: $0 URL OUTPUT.pdf" >&2
  exit 2
fi

url=$1
output=$2

if ! command -v chrome >/dev/null 2>&1; then
  echo "Chrome executable 'chrome' was not found; adjust the script for your installed browser name." >&2
  exit 127
fi

chrome --headless --no-pdf-header-footer --print-to-pdf="$output" "$url"

if [[ ! -s "$output" ]]; then
  echo "PDF was not created or is empty: $output" >&2
  exit 1
fi

echo "Saved PDF to: $output"

Save it as save-page.sh, make it executable with chmod +x save-page.sh, then run ./save-page.sh https://example.com ./page.pdf. Quoting the URL and output path preserves spaces and shell metacharacters as single arguments. For batch work, add your own logging, retry policy, and per-page verification rather than assuming that a zero exit status means all dynamic content appeared.

Check the result before relying on it

A successful command tells you that the renderer ran; it does not prove that the specific site rendered all content, images, pagination, or logged-in state correctly. Open the PDF or inspect it with your normal PDF tools, especially when using automation. Check whether:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • The expected text and images are present, including content loaded after initial page display.
  • Page breaks, margins, orientation, and any headers or footers match the intended use.
  • The page was accessible in the browser session used by the command. A command-line capture does not automatically inherit your interactive browser’s login state.
  • The saved file is nonempty and was written to the intended path.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

“Command not found”

The executable is not on PATH under that name, or the software is not installed. Check which browser or renderer command your system provides, then substitute that name. The Chrome examples use chrome; some systems name the binary chromium or chromium-browser.

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

The PDF is blank or missing dynamic content

The page may render content asynchronously or depend on JavaScript timers or network responses. Try a documented Chrome timeout or virtual-time budget, then inspect the output. Neither flag guarantees application readiness; some pages require a site-specific readiness condition that the basic CLI command cannot infer.

The command rejects a PDF header flag

Flag support and spelling can vary with the installed Chrome version. Current documentation uses --no-pdf-header-footer; older installations may use --print-to-pdf-no-header. Check the documentation for the browser version you actually run.

WeasyPrint reports CSS warnings or the layout differs

WeasyPrint may not support every CSS property used by a site. Read standard error for unsupported-property warnings, simplify or override the stylesheet if appropriate, and verify the PDF. If the page relies on browser-specific rendering, use Chrome/Chromium instead.

wkhtmltopdf behaves differently from its manual

The upstream manual describes 0.12.6 with patched Qt, but your operating-system package may have different build characteristics. Check the package version and build, then validate the particular options and output on a representative page before using them in a production script.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

The output path fails or the file is empty

Confirm that the parent directory exists and is writable, quote paths containing spaces, and use an explicit output filename. Check the command’s error output and verify the resulting file rather than treating command completion alone as proof of a good capture.

Or skip the browser setup

If you need a hosted screenshot-to-PDF workflow rather than maintaining a local browser or renderer, ScreenshotNeo accepts a URL in one GET request and can return a PDF. Its API can accept and remove cookie/consent banners, newsletter popups, and chat widgets before the capture; those cleanup steps can each be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

For a URL capture, the one-call example is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o page.pdf

See the ScreenshotNeo API documentation for request options and response details. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Does a Bash command convert the entire page or just what is visible?

The output is a paginated PDF produced by the selected renderer; inspect it to confirm the content and page breaks you need.

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

Can I use these commands on a page that requires a login?

Only if the renderer’s browser session has the required authentication state. A command run in a shell does not automatically use your usual interactive browser session.

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.