ScreenshotNeo

BlogHTML to image & PDF

How to Print a Webpage to PDF in Linux

Save a webpage as a PDF in Linux with Firefox or Chrome, or automate the job with Chrome Headless. Includes print settings, troubleshooting, and an API option.

By the ScreenshotNeo team4 October 20265 min read

The quickest way: open the webpage in Firefox or Chrome, open Print, choose the browser’s PDF destination, review the preview, and save. For repeatable command-line captures, Chrome Headless can print a URL directly to a PDF file.

1. Save a webpage as a PDF in Firefox

  1. Open the webpage in Firefox.
  2. Open the menu and choose Print… to open print preview. You can also use Ctrl+P.
  3. Set Destination to Save to PDF.
  4. Review the preview and adjust settings such as orientation, page selection, paper size, scale, margins, headers and footers, or print backgrounds.
  5. Select Print, choose a filename and location, then save.

Websites can use print-specific styles, so a page may look different on paper than on screen. Check the preview, especially for pages with complex layouts, long tables, or background colors. See Mozilla’s Firefox print instructions.

2. Save a webpage as a PDF in Chrome

  1. Open the webpage in Chrome and press Ctrl+P on Linux.
  2. Choose the PDF destination available in your installation, commonly Save as PDF.
  3. Review the print settings and preview, then save the file.

The exact destination label can vary with the installed print interface. Choose the PDF option shown in your browser. Google’s Chrome printing guide describes selecting a destination and changing print settings.

3. Create a PDF from the Linux command line with Chrome

For repeatable captures, Chrome Headless can print a URL without opening a visible browser window. The following command writes output.pdf to the current working directory:

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

On some systems the executable may be named google-chrome or chromium. Use the command name provided by your installation. This guide does not prescribe a package installation command because Linux package names and repositories vary by distribution.

Common command options

Option What it does Example
--print-to-pdf Prints the page at the specified URL to a PDF file, normally named output.pdf in the current directory. --print-to-pdf https://example.com/
--no-pdf-header-footer Omits Chrome’s generated header and footer. --print-to-pdf --no-pdf-header-footer https://example.com/
--timeout=5000 Waits up to 5,000 milliseconds before capturing, even if the page is still loading. --print-to-pdf --timeout=5000 https://example.com/

For example, omit generated headers and allow up to five seconds for content to appear:

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

Chrome documents --print-to-pdf, --no-pdf-header-footer, and additional headless options in its Headless command-line reference. Older Chrome versions may use the former header option name --print-to-pdf-no-header.

Choose a sensible wait for dynamic pages

A page may fill in data or images after its initial load. Increase the timeout when the PDF is missing content, then inspect the result. The timeout is a maximum wait, not a guarantee that every script, access check, or delayed request has finished. Chrome’s documentation also shows --virtual-time-budget=42000 for advancing virtual time in a timer example; that value is an example, not a universal setting for webpage capture.

4. Choose the right method

Your need Use What to check
Save one page and adjust its appearance Firefox or Chrome print preview Page range, orientation, paper size, scale, margins, headers and footers, and backgrounds.
Capture URLs repeatedly from a script or terminal Chrome Headless Output location, header/footer behavior, capture timing, and installed browser version.
Print an existing PDF on paper Desktop print workflow or CUPS Selected printer and printer-supported options.

CUPS is for sending files to printers; it is not required for the browser workflows above to create a PDF file. See the CUPS command-line printing documentation. The cited sources do not establish that one browser produces more faithful PDFs than another; check the particular page and browser version you use.

5. Troubleshooting

Problem Likely cause What to try
The PDF layout differs from the screen. The website may use print-specific styles or paper layout rules. Inspect print preview. Adjust orientation, scale, margins, paper size, and background printing.
Chrome says the command was not found. The browser executable has a different name or is not available on the command path. Use the executable name supplied by your Linux installation and check that Chrome or Chromium is installed.
The PDF is saved somewhere unexpected. The command writes its default output in the current working directory. Run the command from the directory where you want output.pdf, then check that directory.
Chrome adds a date, title, URL, or page numbers. Generated PDF headers and footers are enabled. Add --no-pdf-header-footer. On older versions, the former flag may be --print-to-pdf-no-header.
Images or dynamically loaded text are missing. The page may still be loading when capture begins, or its scripts may need more time. Try a longer --timeout and inspect the PDF. The timeout sets a maximum wait; it cannot guarantee that all page content will become available.
A site shows a CAPTCHA, access-denied page, or login screen. The site may restrict automated or unauthenticated access. Use the site in a normal browser session where you have access. Headless printing cannot guarantee access or bypass site controls.
The PDF is blank or incomplete. The page may have failed to load, rely on delayed content, or render differently for printing. Open the URL in the browser first, inspect its print preview, and try a longer headless wait if needed.

6. Reliability, performance, and cost

For a one-off document, print preview is useful because you can inspect pagination and layout before saving. For repeated captures, headless Chrome makes the URL and options scriptable, but results still depend on page behavior, network access, browser version, and capture timing. Validate the generated file when completeness matters.

The documented command-line workflow has no separate PDF service fee, but it requires a browser installation and the resources to run it. Longer waits can make each capture take longer. A browser-generated PDF is also subject to a site’s print styles and access restrictions.

7. Or skip the browser setup

If you need an image or PDF capture through an API, ScreenshotNeo takes a URL in one request and returns a screenshot or PDF. Its API documentation is at screenshotneo.com/docs. For a screenshot request:

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

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server lets AI agents use screenshot, page-info, and PDF capture tools. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

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

FAQ

Do I need CUPS to save a webpage as a PDF?

No. The browser’s PDF destination creates the file. CUPS is relevant when you want to send a file to a printer.

Can I choose pages or change margins?

Firefox print preview offers page selection and settings such as margins, paper size, scale, and orientation. Browser controls can vary, so review the preview before saving.

Does a five-second timeout mean the page is fully rendered?

No. It is an upper limit on the wait before capture. Check the PDF and adjust the wait for the page you are capturing.

Can headless Chrome create a PDF of any URL?

It can attempt to print a URL, but access controls, failed loads, and page-specific rendering behavior can affect the result.