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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Automation

How to Print a PDF With Headless Chrome on Ubuntu

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

On Ubuntu, Headless Chrome creates a PDF file directly from a URL or local page; it does not send anything to a physical printer. The core command is:

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

Chrome writes output.pdf to the command’s current working directory. Add --no-pdf-header-footer to remove Chrome’s generated date/time header and URL/page-number footer. This guide covers installation checks, timing controls, local pages, troubleshooting, automation, and an API alternative.

What you need before running the command

  • A supported 64-bit Ubuntu system. Google’s Linux help lists Ubuntu 18.04 or later among supported systems.
  • A Chrome installation whose architecture matches your machine. Google’s supported installation path is to download the appropriate .deb package, open it in the system installer, and provide administrator credentials. The package is added to the package manager for updates.
  • Permission to write in the directory where you run the command.
  • The actual Chrome executable name. Google’s package commonly provides google-chrome; other packaging choices may expose chrome or another name.

The graphical installation instructions do not prescribe one universal apt install command. Check the current Chrome download page for the package and architecture appropriate to your Ubuntu installation.

Find and verify the executable

Try the name supplied by your package:

command -v google-chrome
google-chrome --version

If that returns nothing, try:

command -v chrome
chrome --version

Use whichever command returns a path and version in the examples below. If neither exists, install Chrome first and verify that the package architecture matches your system.

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

Print a web page to PDF

Run this from the directory where you want the file:

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

Replace the executable name and URL as necessary. The Chrome for Developers command-line reference documents that --print-to-pdf saves the target as output.pdf in the current working directory.

Confirm the output location

pwd
ls -lh output.pdf
file output.pdf

pwd shows the directory Chrome used. If an older file already exists, remove or rename it before a new run so you can tell which PDF was produced:

rm -f output.pdf
google-chrome --headless --print-to-pdf https://example.com/
ls -lh output.pdf

The reviewed current command reference explicitly documents the default filename. Destination-path syntax has varied in examples and versions, so keep the verified default for a portable recipe or validate any custom-output option against the Chrome version installed on your system.

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.

Remove the header and footer

Chrome’s generated print furniture can be removed with:

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

This omits the automatically generated date/time header and URL/page-number footer. Older Chrome releases used --print-to-pdf-no-header; if the newer flag is rejected, check the installed version’s command-line help and use the option it supports.

Wait for JavaScript and delayed content

Headless capture timing matters for dashboards, single-page applications, charts, and pages that load content after the initial document. A PDF can be valid yet incomplete if capture happens before those requests finish.

Set a maximum real-time wait

google-chrome --headless --print-to-pdf --timeout=5000 https://example.com/

--timeout=5000 sets a maximum capture wait of five seconds. It is a timing control, not a guarantee that every site-specific request will finish. Increase it when the page needs more time, then inspect the PDF rather than assuming the delay was sufficient.

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.

Advance virtual page time

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

--virtual-time-budget=5000 advances virtual time for page code such as setTimeout and setInterval. Chrome’s documentation describes this as a faster-running alternative to waiting five real seconds when simulating elapsed page time. Choose the budget from the page’s behavior and verify the rendered result.

Use both controls when appropriate

google-chrome --headless --print-to-pdf --no-pdf-header-footer --timeout=10000 --virtual-time-budget=5000 https://example.com/

The timeout limits the overall capture wait, while the virtual-time budget lets timer-driven code progress. Neither flag waits for a particular selector, understands an application’s readiness state, or fixes a page that fails to load.

Useful variations and edge cases

Local files

For a local HTML document, pass a file URL with an absolute path:

google-chrome --headless --print-to-pdf file:///home/ubuntu/site/index.html

Use an absolute path and URL-escape special characters when necessary. Relative paths are not file URLs and can be interpreted incorrectly.

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

Locally served applications

Start your development server, then capture its HTTP URL:

google-chrome --headless --print-to-pdf --virtual-time-budget=3000 http://127.0.0.1:3000/

The server must be reachable from the same environment where Chrome runs. If it is inside a container or virtual machine, use an address that is reachable from that container or VM rather than assuming the host’s localhost is visible.

Chrome-internal pages

For a chrome:// URL, Chrome requires --allow-chrome-scheme-url, documented as available from Chrome 123:

google-chrome --headless --allow-chrome-scheme-url --print-to-pdf chrome://version

This is rarely needed for ordinary websites and should not be added to normal captures.

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

Headless terminology and versions

Chrome’s February 2023 announcement described the newer unified headless implementation and the then-new --headless=new opt-in. For current usage, follow the current command reference and use ordinary --headless in the PDF example. Chromium’s Headless documentation states that beginning with M132, the old headless-shell functionality is no longer part of the Chrome binary; workflows that specifically require that implementation should use the separate chrome-headless-shell binary instead.

Automation from an Ubuntu script

A shell script can fail clearly when Chrome is missing or when no PDF is produced:

#!/usr/bin/env bash
set -eu

CHROME="$(command -v google-chrome || command -v chrome || true)"
if [ -z "$CHROME" ]; then
  echo "Chrome executable not found" >&2
  exit 1
fi

rm -f output.pdf
"$CHROME" --headless --print-to-pdf --no-pdf-header-footer --timeout=10000 "$1"

if [ ! -s output.pdf ]; then
  echo "Chrome did not create a non-empty output.pdf" >&2
  exit 1
fi
printf 'Created %sn' "$PWD/output.pdf"

Save it as page-to-pdf.sh, make it executable with chmod +x page-to-pdf.sh, and run ./page-to-pdf.sh https://example.com/. This script intentionally relies on Chrome’s documented default filename rather than an unverified destination flag.

Troubleshooting

“command not found” or Chrome will not start

  • Run command -v google-chrome and command -v chrome; the binary name may differ from the package name.
  • Confirm that Chrome is installed for the machine’s architecture and that your Ubuntu release is supported.
  • Run the executable’s --version command directly to separate an installation problem from a PDF problem.

No PDF appears

  • Run pwd and look for output.pdf in that directory.
  • Check write permission with touch test-write && rm test-write.
  • Remove an old output file and rerun so a stale PDF is not mistaken for a new result.

The PDF is blank or missing late content

  • Increase --timeout and/or --virtual-time-budget.
  • Open the URL normally to check whether it requires login, a consent interaction, a bot check, or a network only available in your desktop session.
  • Inspect the PDF after each timing change. These flags cannot guarantee completion for every asynchronous application.

The header or footer remains

Use --no-pdf-header-footer. If your installed release reports an unknown option, consult that version’s help; older releases used --print-to-pdf-no-header.

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

A local page cannot load

Use an absolute file:/// URL for a file, or start the local server and capture its reachable HTTP address. Check that the page’s referenced CSS, JavaScript, fonts, and images are also accessible from the Chrome process.

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 your goal is a reliable screenshot or PDF endpoint rather than maintaining a Chrome process on Ubuntu, ScreenshotNeo provides a website screenshot API and MCP server. It accepts a URL in one request and can return PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled.

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 documentation for request options. Failed bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

Every plan includes features such as full-page capture with lazy images loaded, CSS-selector element capture, device presets and custom viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, click and wait actions, request blocking, headers and cookies, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.

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

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free. Create a free ScreenshotNeo account to try it without a card.

Cost, reliability, and security considerations

  • Headless Chrome itself creates a local file; the command does not require a printer, paper, or a screenshot service.
  • Capture time depends on page complexity, network access, JavaScript, fonts, images, and your selected timing budget. No general success-rate or speed figure is established by the cited Chrome documentation.
  • URLs may contain private data. Avoid placing secrets in shell history, logs, or publicly readable output directories. Treat downloaded PDFs as potentially sensitive.
  • For repeatable jobs, pin and document the Chrome package version, verify the executable path, use a writable working directory, and check that the resulting file is non-empty before passing it to the next step.

Frequently Asked Questions

Does Headless Chrome print on paper?

No. --print-to-pdf creates output.pdf; use a separate operating-system print workflow if you need paper.

Where does Chrome save the PDF?

By default, output.pdf is written to the current working directory shown by pwd.

Which flag removes Chrome’s date and URL footer?

Use --no-pdf-header-footer; older versions may recognize --print-to-pdf-no-header instead.

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

Why is a page incomplete even though Chrome produced a PDF?

Capture can occur before delayed JavaScript or network requests finish. Try a larger --timeout or --virtual-time-budget, then inspect the result.

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.

Read next

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.