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

To convert a web page to PDF with Chrome in Docker, run Chrome in headless mode and pass --print-to-pdf with an output path, for example chrome --headless --print-to-pdf=/out/page.pdf https://example.com/. Make sure the output directory exists and is writable by the container user. A properly configured container user means you do not automatically need --no-sandbox; Chrome’s container FAQ explicitly says it is not needed when the container is set up with a user properly.

Print a URL to PDF with the Chrome command line

For a one-off conversion, invoke the Chrome binary installed in your container and supply the page URL:

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

This prints the URL to the specified PDF path. Chrome’s documented default, if you omit the output path, is output.pdf in the current working directory. An explicit path is usually easier to manage in a container because it makes the output location unambiguous. The command and output behavior are documented in the Chrome Headless shell guide and Headless command-line reference.

The command assumes the Chrome executable is available as chrome. The executable name and installation procedure depend on the image and browser build you choose; confirm the installed binary and its supported flags rather than assuming one package recipe works across images.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
  1. Choose a Chrome build and container image. Install or use a build that provides the Chrome binary you intend to run. The official documentation does not prescribe a Docker base image, package installation sequence, or dependency list.
  2. Provide writable paths. Create the output directory and ensure the runtime user can write the PDF there. Also identify where Chrome will keep any profile or temporary files required by your chosen setup.
  3. Run the headless print command. Pass --headless, --print-to-pdf with the output path, and the URL. If you need to suppress print headers and footers, add the flag described below.
  4. Check the generated file. Confirm the process completed and the PDF exists at the expected path. A successful process launch alone does not establish that the page’s dynamic content had finished rendering before printing.

What headless mode means in Docker

Headless Chrome runs without displaying a visible browser UI, which suits unattended work such as container jobs. Current Headless mode uses the same Chrome browser implementation as headful mode. Chrome introduced the unified implementation in version 112; from version 132.0.6793.0, the old Headless implementation is available only as a standalone chrome-headless-shell binary. These distinctions matter if an existing Docker image or script uses the older shell: do not treat that binary and current Chrome’s --headless mode as interchangeable without checking which one the image contains. See the Chrome Headless mode guide.

Handle headers, footers, and pages that render late

Remove the printed header and footer

Chrome’s command-line reference documents --no-pdf-header-footer for suppressing the print header and footer, including details such as the date, URL, and page number. Add it to the command when those browser-generated details do not belong in the PDF:

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

The reference notes that older Chrome versions may use the earlier spelling --print-to-pdf-no-header. Check the flag supported by the Chrome binary actually installed in your container; the reference labels its last update as 2024-10-21 UTC. Source: Chrome Headless command-line reference.

Allow a bounded wait for client-side content

A page may initially load before its JavaScript has populated the content you want to print. Chrome documents --timeout as a maximum wait before capture and --virtual-time-budget as a way to advance time-dependent page code. For example:

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

The values above are examples from Chrome’s documentation, not recommended defaults. A timeout is a bound on waiting, not proof that every network request or asynchronous operation has completed. A virtual-time budget advances page code’s time-dependent behavior; it is not a universal guarantee that a particular site’s work is finished. Choose and validate a wait strategy against the pages you actually print. For finer navigation and wait control, use an automation library rather than assuming one fixed delay fits every page.

Choose between Chrome CLI, Puppeteer, and Selenium

Approach Best suited to Things to account for
Chrome CLI One URL or a simple batch script Process startup, flags supported by the installed version, output path, and capture timing
Puppeteer An application that needs browser-controlled navigation, waits, or repeated jobs Runtime integration, browser-version management, and the page-ready condition
Selenium-WebDriver A workflow that already uses WebDriver-based browser automation Driver/browser compatibility and fit with existing test infrastructure

Chrome’s Headless overview documents Puppeteer and Selenium-WebDriver as automation approaches. The official pages do not publish a Docker performance comparison or recommend one option for every workload. Select based on how much control your application needs, then validate browser compatibility and capture behavior in the container you deploy.

Why Chrome may not need --no-sandbox

Many container snippets add --no-sandbox by default. Chrome’s archived Headless shell FAQ says: “Note: --no-sandbox is not needed if you properly setup a user in the container.” The useful takeaway is not that any Dockerfile with a non-root user is automatically secure; it is that disabling Chrome’s sandbox should not be treated as a universal Docker requirement. The official note gives a condition but does not supply a complete container-hardening procedure. See the Chrome Headless shell guide.

For a production deployment, document and validate the combination you actually use: the base image, Chrome build, runtime user, writable profile and output paths, and any restrictions imposed by your container environment. If the process fails under those restrictions, investigate the specific Chrome and container error rather than reflexively disabling the sandbox. The official documentation does not enumerate every restriction or provide a complete Docker security configuration.

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

Or skip the browser setup

If your actual need is a clean capture of a public web page rather than a self-managed Chrome-in-Docker PDF pipeline, ScreenshotNeo provides a one-call website screenshot API. This runnable cURL example saves a WebP capture:

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

See the ScreenshotNeo API documentation for request options, including PDF output. ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses report the page verdict and billing status in headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month, with no card required.

Troubleshoot common Docker conversion problems

Chrome cannot write the PDF

Check that the output directory exists inside the container and is writable by the user running Chrome. Use an explicit container path, such as /out/page.pdf, and verify that your container’s mounted output location maps to the path you expect. The Chrome documentation specifies where its default file is written but does not prescribe Docker volume configuration.

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.

The output is missing or appears in the wrong place

When no explicit output path is given, Chrome writes output.pdf to the current working directory. Set --print-to-pdf=/out/page.pdf and check that path inside the container rather than assuming the file appears on the host automatically.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

The PDF omits content rendered by JavaScript

The capture may be occurring before the content appears. Try a bounded --timeout or a suitable --virtual-time-budget, then inspect whether the target page’s own asynchronous work takes longer or needs a specific readiness condition. Neither flag guarantees every site is finished. For page-specific waits and navigation control, use Puppeteer or Selenium-WebDriver.

A command-line flag is rejected

Flags can vary by Chrome build and age. Confirm the browser version and check its supported command-line options. In particular, the print-header flag has an older spelling in some Chrome versions; current documentation uses --no-pdf-header-footer.

Chrome fails when the sandbox is enabled

Do not assume the right fix is to add --no-sandbox. Check the container runtime user and the configuration of the selected image, and review the specific launch error. Chrome’s stated condition is that the container be set up with a user properly; its FAQ does not define every step needed for a particular image or runtime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

The official Chrome pages describe flags and automation options, but do not establish Docker conversion speeds, memory consumption, image size, or comparative reliability. Those measurements depend on the page, browser build, container image, and deployment environment; benchmark your own workload rather than relying on a generic figure. For repeated jobs, account for process startup and browser-version management, and choose a wait strategy that reflects the pages being printed. The official Chrome pages provide no basis for a universal resource estimate or for a particular Docker base image.

For a self-hosted workflow, your costs and operational burden depend on the infrastructure and browser lifecycle you choose; no provider or price is established here. A managed capture API avoids operating the browser container for the capture itself, but is a different workflow from running Chrome locally and should be selected only if its output and behavior fit your use case.

Frequently Asked Questions

Does Chrome’s PDF command work without a desktop display?

Yes. Headless mode runs without a visible browser UI; use the installed Chrome binary with --headless and --print-to-pdf.

Which Chrome Headless implementation does this command target?

It targets current Chrome Headless mode. Chrome 132.0.6793.0 and later make the old Headless implementation available only as a separate chrome-headless-shell binary.

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.

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.