ScreenshotNeo

BlogComparisons

HTML to PDF: Chrome Print Settings vs. Browser Automation

Choose Chrome’s print flow for occasional saves or automate PDF generation with Headless Chrome or Puppeteer for repeatable jobs. Compare styling, readiness, and output options.

By the ScreenshotNeo team4 October 20267 min read

Should you save a page as a PDF through Chrome’s print settings, or generate PDFs with browser automation? Use Chrome’s visible print flow when a person is saving a page occasionally and can inspect the result. Use Headless Chrome or Puppeteer when PDF creation must run repeatedly from a command or application. The choice affects how you control print styling, page readiness, headers and footers, and color. The documentation does not establish a universal speed, quality, or cost winner.

Choose the workflow that fits the job

Need Choose Reason
Save a page once and adjust the result interactively Chrome print flow You can inspect the preview and change the available print settings for that save.
Create PDFs from a script or recurring job Headless Chrome or Puppeteer A command or API call can be incorporated into a repeatable workflow.
Keep print-specific styles Either Inspect Chrome’s preview; Puppeteer uses print CSS by default.
Render the page’s screen styles through Puppeteer Puppeteer with screen media emulation Set the media type to screen before calling page.pdf().

The automation choice follows from the CLI and API interfaces; it is not a claim that automation is faster or produces better output. Dynamic sites may need application-specific readiness handling whichever method you use.

Use Chrome’s print settings for an occasional PDF

  1. Open the page in Chrome and wait until the content you need is visible.
  2. Open Chrome’s print interface and inspect the preview.
  3. Adjust the available print settings for the document, including layout, pages, margins, scale, and headers or footers where offered.
  4. Check that important backgrounds, images, and page breaks appear as intended.
  5. Save the PDF and open it once to verify the result.

This workflow is useful when the page is already open and a person can judge whether it is ready. Print preview is also a practical way to catch a page whose print styles hide content or whose layout breaks across pages.

Generate PDFs with Headless Chrome

Chrome Headless can print a target page directly to a PDF file. A basic command is:

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

Depending on how Chrome is installed, the executable may be named google-chrome, chromium, or something else. Replace chrome with the path or command available in your environment. The documented flag --print-to-pdf saves the target page to the requested PDF output.

To omit Chrome’s print header and footer, add:

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

Older Chrome versions may require --print-to-pdf-no-header. Confirm which flag your deployed Chrome version supports before relying on it. [Chrome Headless command-line reference]

Control capture timing carefully

Chrome documents two distinct timing controls:

  • --timeout=MS sets a maximum wait in milliseconds before capture, even if the page is still loading.
  • --virtual-time-budget=MS advances time-dependent page code as though that amount of time had passed.

For example:

chrome --headless \
  --timeout=10000 \
  --virtual-time-budget=5000 \
  --print-to-pdf=output.pdf \
  https://example.com

These controls do not prove that every asynchronous request has completed. If a page loads content from an API, triggers lazy loading, or waits on application state, verify readiness for that page rather than treating a timeout as a readiness signal.

Generate PDFs with Puppeteer

Puppeteer’s Page.pdf() creates a PDF using print CSS media by default. The guide’s basic flow is to navigate to a page and then call page.pdf(). This Node.js example is runnable after installing Puppeteer and its browser dependency:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({ headless: true });
try {
  const page = await browser.newPage();
  await page.goto('https://example.com', { waitUntil: 'networkidle0' });
  await page.pdf({ path: 'output.pdf', format: 'A4' });
} finally {
  await browser.close();
}

networkidle0 is one possible navigation wait condition, not a guarantee that every application has finished its work. Choose readiness logic to match the target site. Puppeteer documents that PDF generation waits for fonts by default, but that does not guarantee that arbitrary application data, images, or late-running scripts are ready. [Puppeteer PDF generation guide]

Because print media is the default for page.pdf(), CSS rules such as @media print can change what appears compared with the normal browser view. To render with screen media instead, set it before generating the PDF:

await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styles.pdf', format: 'A4' });

Puppeteer says PDF colors are modified for printing by default. To request exact colors, a page can use the CSS property -webkit-print-color-adjust. For example:

@media print {
  body {
    -webkit-print-color-adjust: exact;
  }
}

Check the generated PDF for the specific page and the Chrome and Puppeteer versions you deploy. Color behavior should be a deliberate choice, not an assumption that the PDF will match the screen pixel for pixel. [Puppeteer Page.pdf() API reference]

Set PDF output options

page.pdf() accepts options such as output path and paper format; consult the API reference for the supported options in your installed version. Choose settings based on the document’s purpose, then inspect the result. In particular, decide whether you need print or screen media and whether page backgrounds and headers or footers belong in the output.

Validate the result before relying on it

  1. Check content: confirm the expected sections, images, and fonts are present.
  2. Check pagination: look for clipped tables, split headings, and awkward page breaks.
  3. Check styling: compare print and screen media intentionally; verify background colors if they matter.
  4. Check timing: ensure asynchronous content is present before generation.
  5. Check metadata and destination: confirm the output path is writable and the resulting PDF opens.

Reliability, performance, and cost

The cited documentation describes features, not comparative benchmarks. It does not show that one workflow is universally faster, more reliable, or cheaper. Manual printing requires a person and is suited to occasional saves; automation makes the generation step repeatable, but your application must manage browser startup, page readiness, output files, and failures.

For automated generation, keep the browser version and launch environment consistent, set an appropriate upper wait bound, and handle navigation or file errors in the surrounding job. A timeout limits waiting; it does not make incomplete content correct. Cost depends on your own compute and operational setup, which the documentation does not quantify.

Troubleshooting

Symptom Likely cause What to do
Chrome says the PDF flag is unknown The executable or flag differs for the installed Chrome version. Check the Headless CLI reference and confirm the deployed version; older versions may use --print-to-pdf-no-header for header removal.
The PDF is missing late-loaded content Capture started before application data or scripts completed. Wait for a page-specific readiness condition. Do not assume --timeout or virtual time proves all requests completed.
The PDF looks different from the page on screen Puppeteer uses print CSS by default, or the site has print-specific styles. Inspect print preview, or call page.emulateMediaType('screen') before page.pdf() if screen media is required.
Fonts are missing or layout shifts Fonts or other page resources were not ready, or the document uses a resource unavailable to the browser. Confirm the font loads in the browser and add appropriate readiness handling for site-specific resources. Puppeteer’s font wait does not cover every application resource.
Colors or backgrounds differ Print color adjustment or print CSS changed the output. Inspect the PDF and use -webkit-print-color-adjust: exact when exact print colors are needed; validate against the deployed versions.
PDF generation fails to write a file The destination path may be invalid or not writable. Use a writable path, ensure the parent directory exists, and handle file errors in the calling process.
A command-line capture waits too long or cuts off The page is slow, waits indefinitely, or the configured maximum is too short. Set a suitable timeout and investigate the page’s loading behavior. A longer wait still is not proof that all asynchronous content is ready.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. It returns a screenshot or PDF with one GET request. For a PDF capture:

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

See the ScreenshotNeo API documentation for request options. Cookie banners are accepted like a visitor and removed before the shot; newsletter popups and chat widgets are removed too. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000.

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

FAQ

Can I make a PDF from a URL without opening a visible Chrome window?

Yes. Headless Chrome supports --print-to-pdf, and Puppeteer exposes PDF generation through page.pdf().

Will a generated PDF always match what I see on screen?

No. Print CSS and print color handling can change the output. Puppeteer uses print media by default; emulate screen media when that is the intended result and verify the PDF.

Does waiting for network idle guarantee a complete PDF?

No. It is a navigation wait strategy, not proof that all application data, images, or scripts are ready. Define and verify readiness for the page you are generating.