Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
The quickest way to convert a webpage to PDF from a shell is Chrome Headless:
chrome --headless --print-to-pdf https://example.com/
Chrome writes output.pdf in the current directory by default. For local files, print a file:// URL (or use a document-focused renderer such as WeasyPrint). The best command depends on whether your HTML needs JavaScript, browser-level CSS fidelity, strict local-file controls, or a lightweight print workflow.
Choose the renderer before choosing a command
HTML-to-PDF tools do not all render the same way. Chrome drives a browser engine, WeasyPrint is an HTML/CSS document renderer, and wkhtmltopdf uses Qt WebKit. Select based on the page rather than on the shortest command.
| Tool | Best fit | Important considerations |
|---|---|---|
| Chrome Headless | Modern sites, JavaScript applications, and browser-faithful output | Page scripts must finish before printing; flags and executable paths vary by browser version and operating system. |
| WeasyPrint | Local HTML/CSS documents and print-oriented layouts | CSS support is not universal. Unsupported properties can generate warnings, and untrusted HTML/CSS needs isolation. |
| wkhtmltopdf | Existing workflows that need print-media, JavaScript, page-size, or local-file controls | Its Qt WebKit renderer may differ from current browsers. Verify the installed version and defaults before a new production deployment. |
Whatever you choose, render a representative document and inspect page size, margins, fonts, images, links, page breaks, and dynamically generated content. The commands below are documented usage patterns, not a claim that a particular page will render perfectly without inspection.
#1 Best Overall
Convert a URL with Chrome Headless
Basic conversion
chrome --headless --print-to-pdf https://example.com/
The documented default output is output.pdf in the working directory. Use an absolute executable path if your installation does not put Chrome on PATH; the executable is commonly named differently on Linux, macOS, and Windows.
Set the output file
Chrome versions expose output-path syntax differently. Check the CLI reference for your installed build, then use its supported form (for example, a --print-to-pdf=report.pdf argument). If a flag is rejected, run chrome --help and use the spelling documented by that version rather than copying a command intended for another platform.
Remove print headers and footers
chrome --headless --print-to-pdf --no-pdf-header-footer https://example.com/
This suppresses the browser’s printed URL, title, date, and page-number decorations. It does not remove headers or footers authored in your HTML/CSS.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Control waiting time
chrome --headless --print-to-pdf --timeout=5000 https://example.com/
--timeout=5000 sets a maximum wait of 5,000 milliseconds before capture, including while the page is loading. A timeout is not proof that asynchronous content has completed: an API request, image, font, or client-side render can still be unfinished. Increase the value for known-slow pages, and prefer a page-side readiness signal or a renderer that supports waiting for the condition your workflow needs.
Advance time-dependent JavaScript
chrome --headless --print-to-pdf --virtual-time-budget=42000 https://example.com/
The documented --virtual-time-budget=42000 example advances virtual time before capture, which can help pages whose scripts schedule work. It does not guarantee that external services respond or that every animation has reached the desired state. Disable animations in print CSS or application code when deterministic output matters.
Local HTML files
Pass a correctly formed file URL, quoting it when the path contains spaces:
Rank #2
- LIGHTWEIGHT AND FOLDABLE STRUCTURE: Foldable design (30x6x8cm) and lightweight (1000g) make it portable for travel or home use. Compact shape fits perfectly on your workbench without taking up much space
- SIMPLE CONNECTION: Works with USB connection without the need for additional programs for quick installation. Simple controls make it easy to operate both beginners and regular users with regular size papers
- QUICK DOCUMENT PROCESSING: Automatically scan suggestions one page per second, greatly increase productivity. Ideal for workplaces, schools, legal/financial areas where large capacity is required
- TEXT CONVERSION TECHNOLOGY: Smart OCR function works in over 200 languages, changes scanned files to editable text for easy storage and editing Seamless digital conversion of paper documents improves workflow
- EXCELLENT IMAGEING: Equipped with a 16MP clear camera, this portable document scanner produces crisp, accurate images of documents and keeps important content intact. Perfect for striking scans of contracts, receipts and books
chrome --headless --print-to-pdf "file:///absolute/path/to/input.html"
Relative images, stylesheets, fonts, and scripts must resolve from the local document and remain accessible to the browser. Treat local-file access as sensitive when the input is not fully trusted; do not grant broad filesystem access merely to make a broken asset load.
Convert HTML with WeasyPrint
File or URL to PDF
weasyprint input.html output.pdf
The CLI accepts [options] <input> <output>. Input can be a filename, URL, or - for standard input; output can be a filename or - for standard output.
Add print CSS
weasyprint -s print.css input.html output.pdf
Use the additional stylesheet for page-oriented rules such as margins, page breaks, and print-only visibility. Keep an eye on warnings: unsupported CSS properties can change layout without making the command fail.
Pipe HTML through the shell
cat input.html | weasyprint - output.pdf
For many documents in one long-lived service, WeasyPrint’s guide recommends considering its Python API to avoid paying process-startup cost for every conversion. The CLI remains convenient for scripts, build jobs, and one-off files.
Security boundary
WeasyPrint documents security risks in untrusted HTML and CSS. If users can submit content, run conversion in an isolated process with restricted filesystem and network access, enforce resource and time limits, and validate the allowed input. Do not assume that producing a PDF is a harmless file-format conversion.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use wkhtmltopdf when its controls match your legacy workflow
wkhtmltopdf input.html output.pdf
wkhtmltopdf’s usage documentation includes switches for print media, JavaScript, page dimensions, and local-file access. One security-relevant control is --disable-local-file-access, which prevents a local input from reading other local files unless you explicitly allow them.
Its project documentation identifies Qt WebKit as the rendering engine. That can be useful for a stable existing pipeline, but it is not the same engine as a current Chrome browser. Verify the installed version, defaults, and output against your target pages before making it the basis of a new production workflow. Avoid enabling broad local-file access for untrusted input.
Make output deterministic
Control print CSS
Add an explicit print stylesheet with @page size and margins, hide navigation, and define page-break behavior. Check that your chosen renderer supports the properties you rely on. A browser print preview, WeasyPrint, and wkhtmltopdf can interpret the same CSS differently.
Wait for content intentionally
Single-page applications often populate the DOM after the initial response. A fixed delay can reduce races but cannot prove that data, fonts, or images are ready. Where possible, expose a page-side “ready” condition, freeze animation, and make external dependencies fail visibly rather than silently producing an incomplete PDF.
Free tools Windows power users keep installed
One-click scans. No signup required.
Handle fonts and images
- Use fonts available inside the conversion environment, or package and reference them predictably.
- Use absolute, reachable asset URLs for remote documents and correct
file://paths for local documents. - Check image dimensions and resolution; a PDF can contain an image that is technically loaded but visually missing or blurry.
- Inspect links, selectable text, and page breaks in the resulting PDF rather than relying only on a zero exit status.
Automation patterns
Shell job with failure checks
set -eu
out="report.pdf"
chrome --headless --print-to-pdf="$out" --no-pdf-header-footer "https://example.com/report"
test -s "$out"
Use the output-file syntax accepted by your Chrome build. The final size check catches an empty or missing artifact, but it cannot validate visual correctness.
Standard-input pipeline
generate-html | weasyprint - report.pdf
Keep generated HTML, CSS, and assets reproducible. Log the renderer version and command-line options with each build so a later layout change can be traced to an input or tool update.
Troubleshooting common failures
“Command not found”
Install the renderer, add its executable directory to PATH, or call the absolute path. Confirm with chrome --version, weasyprint --version, or wkhtmltopdf --version.
The PDF is blank or missing application content
The page may require JavaScript, a login, a blocked resource, or more time than the capture allowed. Try Chrome for browser-dependent content, increase or redesign the wait strategy, and inspect network and console errors in a controlled environment.
Recommended Free Tools
Assets or fonts are missing
Check URL resolution, permissions, certificate errors, content types, and whether the process can reach the asset host. For local files, confirm every relative path from the document’s directory and avoid unsafe broad file permissions.
Layout differs from the browser
Compare print CSS and renderer engines. WeasyPrint does not implement every CSS property; wkhtmltopdf uses Qt WebKit; Chrome’s print output can also differ from screen media. Specify page size and margins and test the exact renderer version used in deployment.
Chrome flags fail on one machine
Flags and executable names vary by browser version and platform. Consult that installation’s help and current CLI documentation instead of assuming a flag from another release is available.
Conversion is slow or hangs
Remote scripts, fonts, trackers, infinite animations, and unreachable hosts are common causes. Set an outer process timeout, limit network access, remove unnecessary resources, and record stderr. For repeated WeasyPrint conversions, a long-lived Python process can avoid repeated startup overhead.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsOr skip the browser setup
ScreenshotNeo provides a website screenshot and PDF API when you want one HTTP request instead of installing and maintaining a browser. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
For the PDF/screenshot endpoint, see the ScreenshotNeo API documentation. A minimal request is:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
And Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo includes full-page capture, PDF paper size and margins, custom CSS and JavaScript, waits, cookies and headers, device presets, caching, signed links, asynchronous webhooks, bulk capture, and a usage API. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
Frequently Asked Questions
Can I convert HTML from standard input directly to PDF?
Yes. WeasyPrint accepts - as input, so a command such as cat input.html | weasyprint - output.pdf works.
Which renderer should I use for a JavaScript-heavy site?
Start with Chrome Headless because it captures through a browser engine, then verify that the page’s asynchronous content is ready before printing.
Is wkhtmltopdf equivalent to Chrome?
No. wkhtmltopdf uses Qt WebKit, so modern CSS and browser behavior can differ. Validate the exact pages and installed version before relying on it.
How do I protect a converter that accepts user HTML?
Isolate the process, constrain filesystem and network access, enforce resource and time limits, and avoid enabling JavaScript or broad local-file access unless the workflow requires them.
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.

