For a web page that depends on JavaScript, start with Chrome Headless:
chrome --headless --print-to-pdf https://example.com/
Chrome writes output.pdf in the current directory by default. For a local, mostly static document, WeasyPrint is usually the simpler HTML/CSS-to-PDF command. wkhtmltopdf remains useful when you need its legacy WebKit controls, but verify the installed version and output before adopting it for a new production workflow.
Choose the renderer before you automate
“Convert HTML to PDF” can mean two different jobs: printing a live website, or typesetting a trusted HTML document. The renderer determines whether JavaScript runs, which CSS is supported, how fonts and images are loaded, and what security boundary you need.
| Tool | Best fit | Important considerations |
|---|---|---|
| Chrome Headless | Web pages whose content or layout depends on browser JavaScript | High browser fidelity; asynchronous content still needs a reliable readiness strategy |
| WeasyPrint | Controlled HTML/CSS documents and print-oriented templates | Direct CLI and extra stylesheet support; CSS is not universally supported |
| wkhtmltopdf | Existing workflows that rely on its WebKit-era options | Controls print media, JavaScript, page dimensions and local-file access; validate modern-page compatibility |
None of these commands guarantees a correct PDF for every page. Render a representative document and inspect page size, margins, fonts, images, links, page breaks and generated content before treating the job as production-ready.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problems#1 Best Overall
Convert a URL with Chrome Headless
Basic command
chrome --headless --print-to-pdf https://example.com/
The documented default output is output.pdf in the current working directory. Browser executable names and paths vary by operating system and installation; use the executable available on your system, such as a platform-specific Chrome or Chromium binary.
Remove print headers and footers
chrome --headless --print-to-pdf --no-pdf-header-footer https://example.com/
This suppresses the browser-generated print header and footer. It does not remove headers or footers deliberately created by the page’s own print CSS.
Set a maximum wait
chrome --headless --print-to-pdf --timeout=5000 https://example.com/
--timeout=5000 sets a maximum wait of 5,000 milliseconds before capture. A timeout is not proof that asynchronous data, images or fonts have finished loading; a page can still be incomplete when the timer expires.
Advance time-dependent JavaScript
chrome --headless --print-to-pdf --virtual-time-budget=42000 https://example.com/
The virtual-time budget gives scripts an opportunity to advance timers and render time-dependent content before printing. Use it only after observing how the page behaves; a larger number is not a substitute for an application-specific readiness signal.
Make the capture repeatable
- Use a fixed URL and, where possible, deterministic input data.
- Choose a timeout or virtual-time budget appropriate to the page rather than copying a value blindly.
- Run the command in a clean working directory and name or move the resulting PDF explicitly in your wrapper script.
- Open the PDF and check the actual output, especially content inserted after the initial HTML response.
Chrome’s headless capture executes the page in a browser context. That makes it the natural first choice for dashboards, client-rendered applications and pages whose layout depends on browser behavior, but it also means network access, authentication and third-party scripts can affect the result.
Convert a file, URL or standard input with WeasyPrint
File or URL to PDF
weasyprint input.html output.pdf
The command accepts a URL, a filename, or - for standard input. The output can be a filename or - for standard output. For example, converting a remote page uses the same shape:
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
weasyprint https://example.com/ page.pdf
Apply an additional print stylesheet
weasyprint -s stylesheet.css input.html output.pdf
Use the extra stylesheet for print-specific margins, page breaks, colors or visibility rules. Keep the CSS intentionally within the renderer’s supported feature set and inspect warnings: unsupported properties can change the layout without stopping the command.
Use a pipeline
cat input.html | weasyprint - output.pdf
Standard input is useful when a template is generated by another command. If the HTML references relative images, fonts or stylesheets, make sure their URLs resolve from the document’s base location; a stream without a usable base URL may not find local assets.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Security boundary
WeasyPrint’s documentation warns that untrusted HTML or CSS can create security problems. Do not feed arbitrary user input directly into a process with broad filesystem or network access. Isolate conversion, restrict reachable resources, apply operating-system limits, and use a separate worker for hostile or unknown documents.
Use wkhtmltopdf when its controls match your workflow
Basic conversion
wkhtmltopdf input.html output.pdf
wkhtmltopdf also accepts URLs. Its usage documentation includes options for print media, page dimensions, JavaScript and local-file access, which can be valuable in an established pipeline.
Control local-file access deliberately
The documented --disable-local-file-access behavior prevents a local input from reading other local files unless you specifically allow them. Treat broad local-file access as a privilege, not a default fix for missing assets. If a document needs local images or stylesheets, allow only the directories required by that document.
Check compatibility before standardizing
wkhtmltopdf uses a Qt WebKit renderer. Its project usage text is maintained on the master branch while the project homepage information is older, so verify the exact installed version, defaults and output on your target platform. Do not assume that a modern browser page will render like it does in current Chrome.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Decision guide for common jobs
Choose Chrome Headless when
- The page is a single-page application or injects its content with JavaScript.
- You need behavior close to a current browser.
- You can control authentication, network access and page readiness.
Choose WeasyPrint when
- You own the HTML and want a document-oriented, print stylesheet workflow.
- You need a concise command that reads a file, URL or standard input.
- You can keep your CSS within the engine’s supported subset.
Choose wkhtmltopdf when
- An existing system already depends on its WebKit behavior or option set.
- You need its explicit switches for print media, JavaScript, dimensions or local-file access.
- You have verified the result against the exact installed build.
Make PDF output predictable
Wait for the content you actually need
Network idle or a fixed delay can be useful, but neither proves that an application has finished its business logic. Prefer a page state that is deterministic: server-rendered HTML, a known data fixture, or a readiness marker that your wrapper can observe before invoking the converter. With Chrome’s command alone, inspect pages that load data after the initial response rather than assuming the timeout is sufficient.
Control print layout in HTML and CSS
Define page size, margins, print colors, link treatment and page-break rules in a print stylesheet. Test long tables, headings near page bottoms, images larger than a page, custom fonts and right-to-left text. A successful exit status only means the renderer produced a file; it does not certify visual correctness.
Make assets available
Broken relative URLs, blocked remote resources, missing fonts and authentication-protected images are common causes of blank areas. Run the converter from a predictable directory, use resolvable absolute URLs where appropriate, and provide required credentials through the mechanism supported by your deployment. Avoid exposing secrets in shell history or process listings.
Separate failures from empty documents
Check both the command’s exit status and the resulting PDF. A page can return an HTTP response yet contain no useful content, while a renderer can warn about CSS and still write a file. Keep logs with the generated artifact so an automated job can explain what happened.
Recommended Free Tools
Troubleshoot the failures you will see most often
The command is not found
Install the chosen tool or correct the executable path. In automation, configure the full path explicitly and record the renderer version so a machine change does not silently alter output.
The PDF is blank or missing application data
The page probably captured before JavaScript finished, was blocked by authentication, or failed to load a dependency. Try Chrome Headless with a suitable timeout or virtual-time budget, confirm the URL is reachable from the conversion host, and inspect the page’s own error state. For a static document, use WeasyPrint and remove unnecessary script dependencies.
Images, fonts or CSS are missing
Check relative URL resolution, certificate or network access, content-security restrictions and local-file permissions. With WeasyPrint, review warnings for unsupported CSS. With wkhtmltopdf, use narrowly scoped local-file permissions rather than enabling unrestricted access.
Headers, footers or margins are wrong
For Chrome, add --no-pdf-header-footer when browser-generated decorations are unwanted, then review the page’s print CSS. For any renderer, set and test page dimensions and margins in the document or the tool’s supported options.
The result differs between machines
Pin the browser or converter version, fonts, locale, timezone and input data where your deployment permits. Differences in browser flags, executable paths, network responses and installed fonts can all change pagination.
An untrusted document is dangerous to process
Assume HTML, CSS, JavaScript and referenced resources can be hostile. Run conversion in an isolated worker, limit filesystem and network access, set resource and time limits, and disable JavaScript or local access unless the document requires them. The exact sandbox design depends on your operating environment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability and cost notes
Browser startup is relatively expensive in high-volume jobs. Reusing a long-lived process can reduce repeated startup overhead, but it requires careful isolation between documents. WeasyPrint’s guide similarly recommends considering its Python API in a long-lived process for many documents. Do not share cookies, local storage or credentials between tenants.
Use bounded concurrency, queue work, capture structured logs and retry only failures that are plausibly transient, such as a temporary network error. Retrying a deterministic CSS failure wastes resources. Store the source HTML, renderer version and relevant flags alongside important PDFs so you can reproduce a disputed result.
Best Value
The documentation provides operational flags, not comparative speed or accuracy benchmarks. Treat the choice as a rendering and security decision, then measure your own representative workload.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. It can return PNG, JPEG, WebP or PDF from one GET request, while handling browser setup for you. The service accepts the cookie or consent banner as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; those cleanup steps can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and each response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers.
Here is the supplied one-call example (change the target URL as needed):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For PDF output and options such as paper size, margins, landscape mode and page ranges, use the ScreenshotNeo documentation. The same endpoint also supports full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets, custom viewport and retina scale, custom CSS and JavaScript, click-before-capture, selector hiding, waits for a selector, delay or network idle, request and resource blocking, custom headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, configurable caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work, which can simplify migration.
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)
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 an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. Every plan includes every feature: 1,000 shots per month are free with no card; paid plans start at $5 for 3,000 shots. Sign up for the free ScreenshotNeo plan.
Verify a production conversion
- Render a fixture containing JavaScript, images, fonts, long content and deliberate page breaks.
- Compare the PDF visually with the intended print layout and extract text to check that content is present.
- Test failure paths: unreachable URL, slow dependency, missing asset, invalid CSS and untrusted input.
- Record renderer version, flags, environment and source revision.
- Set limits for time, memory, file size, network access and concurrent jobs.
Frequently Asked Questions
Can a CLI converter print a page that requires login?
Only if the conversion process receives valid authentication in a secure, supported way. A public URL alone does not grant access to private content; design credential handling separately from the shell command.
Should I convert HTML on the client or on a server?
Server-side conversion is easier to standardize for scheduled jobs, but it must be isolated from untrusted input and uncontrolled network access. Client-side conversion can preserve a user’s session but is harder to make reproducible.
Why does a successful command still produce a unusable PDF?
Exit status confirms file creation, not visual or semantic correctness. Inspect the PDF for missing asynchronous content, fonts, images, pagination and links, and retain logs and renderer versions for diagnosis.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick 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.

