How to Capture a Webpage PDF with the Browser Console
Run window.print() in the page’s browser console, choose a PDF destination in the print dialog, review the layout, and save. For unattended output, use Chrome Headless.
To save the page you are viewing as a PDF, open that page’s developer console, run window.print(), choose a PDF destination in the browser’s print dialog, review the preview, and save. The command opens the normal print dialog; it does not select a destination or download a PDF by itself.
Use the browser console
- Open the webpage you want to capture. Make sure you are signed in and that the content you need is visible or loaded.
- Open the browser’s developer tools and select the Console. In Firefox, the Web Console shortcut is Ctrl+Shift+K on Windows/Linux or Cmd+Option+K on macOS. Other browsers and operating systems can use different shortcuts.
- Run this in the page’s console context:
window.print();
print() also works in the page context. The call invokes the browser’s print flow for the current document. If the document is still loading, printing waits for it to finish loading. The call blocks while the print dialog is open, so code after it will not run until the dialog closes.
- In the preview, choose the PDF destination. Chrome commonly labels it Save as PDF; Firefox uses Save to PDF. Labels and available destinations can vary by browser, operating system, and system print dialog.
- Inspect the preview and change settings such as page range, paper size, orientation, scale, margins, background graphics, and headers or footers as needed.
- Choose Save or Print in the dialog, select a location and filename if prompted, and save the PDF.
The console command is a convenient way to trigger the print interface from the page. It does not bypass the dialog or provide a browser-console API for silently writing a PDF file.
Choose the right workflow
| Approach | Best for | PDF saving | Timing and control |
|---|---|---|---|
window.print() |
A quick, manual capture of the open page | You select the PDF destination and save in the dialog | Uses the browser’s print layout and settings |
| Browser print menu or shortcut | The same manual print flow without opening the console | You select the PDF destination and save | Same print preview and controls |
| Chrome Headless | Repeatable command-line or unattended Chrome capture | Writes a PDF file directly | Supports command-line timing and header/footer flags |
| ScreenshotNeo API | Captures called from an application or script without setting up browser automation | Returns a PDF when requested through its API | Supports PDF settings, async jobs, and other capture options |
Check and correct the PDF layout
A webpage’s print rendering can differ from what appears on screen. The site may apply print-specific styles, omit interactive controls, reflow columns, or paginate content differently. Always inspect the preview before saving, especially for long pages, dashboards, articles with background colors, and pages with fixed or sticky elements.
- Content is missing: Scroll through the preview and check page range and scale. Some sites load content only when you scroll; scroll through the webpage first, wait for the content to appear, then run the command again.
- Text is too small or clipped: Adjust scale, orientation, paper size, or margins. A wide table may fit better in landscape orientation, while a long article may need a different scale.
- Colors or images are absent: Enable background graphics if the dialog offers that setting. Some sites also alter colors for print.
- Unwanted page furniture appears: Toggle headers and footers if available. Browser print settings can add the page title, URL, date, or page numbers.
- The page contains clutter: Firefox may offer an Original or Simplified print format. Edge’s Immersive Reader may offer a cleaner route on supported sites. Availability depends on the browser and page.
- The PDF differs from the live page: This can be expected because pages can define print-specific layouts. Use the preview to decide whether the print rendering is suitable.
Browser notes
Chrome
Run window.print() in the page console, then choose Save as PDF in print preview. You can also open the print interface with Ctrl+P on Windows/Linux or Command+P on macOS. The console call triggers the same general print pathway.
Firefox
Run the command in the Web Console, then choose Save to PDF under Destination in the print preview. Firefox provides controls such as paper size, scale, pages per sheet, margins, headers and footers, and background printing; options can vary. Its print rendering may differ from the screen view.
Microsoft Edge
Run the command in the page console, or open printing with Ctrl+P on Windows or Command+P on macOS. Edge’s print controls include settings such as paper size, margins, scale, and background graphics. Immersive Reader can provide a clutter-free alternative on some sites.
Automate PDF output with Chrome Headless
For unattended output, Chrome’s headless command-line mode can print a URL directly to a PDF. This is a separate workflow from the interactive browser console.
chrome --headless --print-to-pdf https://example.com/
The command writes output.pdf in the current working directory. Depending on your system, you may need to use the full path to the Chrome executable or adapt the command for your environment.
Useful documented flags include:
--no-pdf-header-footersuppresses the date/time header and URL/page-number footer.--timeout=5000waits up to five seconds before capture.--virtual-time-budget=42000advances virtual time for time-dependent page code.
For example, combine flags when a page needs time to render and you do not want printed headers or footers:
chrome --headless --print-to-pdf --no-pdf-header-footer --timeout=5000 https://example.com/
Timing flags are not a guarantee that every page is ready. A page may depend on authentication, delayed network requests, user interaction, or content that appears only after scrolling. Confirm that the resulting PDF contains the needed content and adjust the URL, executable path, and wait strategy for your environment.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. It can return a PDF from one API request; see the API documentation for PDF parameters and other options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=pdf -o page.pdf
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com", "format": "pdf"},
timeout=90,
)
r.raise_for_status()
open("page.pdf", "wb").write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://stripe.com',
format: 'pdf'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo request failed: ${res.status}`);
await Bun.write('page.pdf', res);
Replace the example URL and supply your API key. The cURL and Python snippets save the response bytes; the Node.js example uses Bun’s file-writing helper. In Node.js, use fs/promises to write the response if Bun is not available. ScreenshotNeo accepts PDF settings such as paper size, margins, landscape orientation, and page ranges.
- Cookie banners are accepted and removed before capture, along with 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
- Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers say the page verdict and whether the request was billed.
- An MCP server lets AI agents use
take_screenshot,get_page_info, andcapture_pdf. - The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo and get 1,000 screenshots a month free, with no card.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
window.print is not a function or the command errors |
The console is not running in the webpage’s context, or the expression was entered incorrectly. | Select the page’s execution context in developer tools and enter window.print(). |
| The browser warns about pasting code | Developer tools may block pasting to protect against self-XSS. | Do not paste unfamiliar code. Type the simple print command yourself if you choose to proceed, following the browser’s own instructions. |
| A print dialog does not appear | The call may have run in a different frame or context, or the browser may already have a print dialog open. | Close any existing dialog, select the intended page context, and run the command again. You can also use the browser’s print menu or shortcut. |
| No PDF option is visible | The destination name and available PDF printer depend on the browser and operating system. | Look for a Save to PDF or Save as PDF destination in the dialog. On some systems, PDF saving is provided by the system print dialog. |
| Output is blank or incomplete | The page may still be loading, require authentication, load content on scroll, or have print-specific styles. | Confirm the page is fully loaded and signed in, scroll to trigger lazy content, then print again and inspect the preview. |
| Headless command cannot find Chrome | The executable name or path differs on your system. | Use the installed Chrome executable’s full path and check command syntax for your environment. |
| Headless PDF misses late content | The page needs more time or depends on a condition the timeout does not cover. | Adjust the timeout or virtual time budget and check whether the content requires interaction, scrolling, or authentication. |
| PDF has an unexpected header or footer | Print settings add page metadata. | Disable headers and footers in the dialog, or use Chrome Headless with --no-pdf-header-footer. |
Performance, reliability, and cost
window.print() uses the browser and site already open, so it needs no additional library or service. It is best for occasional, attended captures. The print dialog pauses the calling page context while open, and the save step remains manual.
For repeatable tasks, headless Chrome makes the capture command scriptable and writes a PDF file without a human selecting a destination. Rendering time still depends on the page and its network or application state. Set a reasonable wait, check the output, and handle failed commands in the surrounding script.
The console and Chrome Headless methods use browser software already available to you; no screenshot API charge is involved. An API such as ScreenshotNeo has plan limits and pricing, but can avoid maintaining browser setup and offers PDF options, batch capture, caching, and async jobs. ScreenshotNeo’s listed plans range from 1,000 free screenshots a month to paid plans starting at $5 for 3,000; check its site for the current plan details.
FAQ
Can the console save the PDF without asking me anything?
No. window.print() opens the browser’s print dialog. You choose the PDF destination and complete the save action.
Does this capture the whole webpage?
It prints the current document according to the site’s print layout and the browser’s pagination. For pages that load content as you scroll, scroll through the page first and inspect the preview for missing sections.
Can I use this on any browser or phone?
The JavaScript print method is a browser feature, but access to developer tools and PDF destinations varies. These steps describe desktop browser workflows; mobile browser interfaces differ.
Can a website prevent printing?
A site can create a poor or restricted print experience through its page design, scripts, or print styles. If the page is accessible to you, try the browser’s normal print preview, a supported simplified reading view, or an authorized PDF export offered by the site.


