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
.debpackage, 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 exposechromeor 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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
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.
Remove the header and footer
Chrome’s generated print furniture can be removed with:
Rank #2
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.
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.
Rank #3
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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsLocally 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:
Rank #4
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.
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-chromeandcommand -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
--versioncommand directly to separate an installation problem from a PDF problem.
No PDF appears
- Run
pwdand look foroutput.pdfin 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
--timeoutand/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.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBest Value
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.
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.
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.
Recommended Free Tools
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.
Quick Recap
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.




