How to Capture a Webpage as a PDF with wkhtmltopdf on Windows
Install wkhtmltopdf on Windows, convert a webpage to PDF, adjust page layout, and troubleshoot common issues safely.
Quick answer: Install or extract the Windows build of wkhtmltopdf from the official downloads page, then run this in Command Prompt or PowerShell:
wkhtmltopdf https://example.com C:\Users\you\Downloads\page.pdf
Replace the URL and destination with your own. Quote a Windows path that contains spaces. This guide covers the basic conversion, page layout options, troubleshooting, and the safety limits to keep in mind.
1. Install wkhtmltopdf and check the command
wkhtmltopdf is an open-source command-line tool that renders HTML to PDF using Qt WebKit. It runs headlessly, so it does not require a display service. The project describes it as LGPLv3 software. The official downloads page lists Windows installers for 32-bit and 64-bit systems, plus 7z archives for older Windows targets.
The project page lists version 0.12.6 as its stable series, released June 11, 2020. Because that release information is old, check the official downloads page for the available asset and confirm that it fits your Windows environment before installing.
- Open the official downloads page and choose the Windows installer or archive appropriate for your system.
- Install the program, or extract the archive to a directory you can access.
- Open Command Prompt or PowerShell and check whether Windows can locate the executable:
wkhtmltopdf --version - If Windows reports that the command is not recognized, run
wkhtmltopdf.exeby its full path, or add its installed directory to PATH. Installers can differ, so check where yours placed the executable.
2. Convert a webpage to PDF
The basic command takes a source URL followed by the destination PDF path:
wkhtmltopdf https://example.com C:\Users\you\Downloads\page.pdf
For a destination directory or filename containing spaces, enclose the path in double quotes:
wkhtmltopdf https://example.com "C:\Users\you\Downloads\annual report.pdf"
To use the command when it is not on PATH, provide the executable’s full path. For example, substitute the location where it was installed:
"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" https://example.com "C:\Users\you\Downloads\page.pdf"
When the command completes, open the output PDF and check that the page content and layout are usable. This is especially important for pages with scripts, dynamic content, or layouts that depend on a particular screen size.
3. Set page size, orientation, margins, and headers
Start with a successful basic conversion, then add layout options. The manual documents page size, orientation, margins, grayscale output, image quality, and headers and footers. These examples show the command syntax; they are not a guarantee that every website will render identically on every Windows installation.
Choose paper size and orientation
wkhtmltopdf --page-size Letter --orientation Landscape https://example.com "C:\Reports\page.pdf"
Use --page-size A4 or --page-size Letter for those common paper formats. Choose --orientation Portrait or --orientation Landscape to control page orientation.
Set margins
The manual provides margin controls, including top, bottom, left, and right margins. For example, a command can specify individual margins:
wkhtmltopdf --margin-top 15mm --margin-bottom 15mm --margin-left 12mm --margin-right 12mm https://example.com "C:\Reports\page.pdf"
Adjust the units and values to suit the document. If content is clipped, try wider margins or a different paper size and orientation.
Add a header or footer
Headers and footers can use placeholders such as [page], [topage], [webpage], and [title]. Consult the wkhtmltopdf usage manual for the exact header and footer options and formatting supported by your build.
Other output controls
The usage manual also documents grayscale output and image quality controls. Use these when the output requirements call for monochrome pages or different image handling. Review the manual for option names and accepted values for the installed version rather than guessing at a setting.
4. Safety and rendering limits
Do not convert untrusted HTML or JavaScript without sanitizing it. The official downloads page warns that unsanitized user-supplied HTML or JavaScript can lead to complete takeover of the server running wkhtmltopdf. This warning matters most when a service accepts content from users, processes uploaded files, or performs conversions in a server-side batch job. Treat conversion input as executable content and sanitize it before processing.
wkhtmltopdf uses Qt WebKit. The research for this guide does not establish that it reliably renders modern JavaScript-heavy pages or that it is compatible with every current Windows environment. If a site depends on scripts to produce its content, inspect the generated PDF rather than assuming the page finished rendering correctly.
5. Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
wkhtmltopdf is not recognized |
The executable is not on PATH, or the installation or extraction location differs. | Locate wkhtmltopdf.exe and invoke it using its full path. If appropriate for your setup, add its directory to PATH. |
| Output path is rejected or a file is created in the wrong place | The destination path is misspelled, its directory does not exist, or the path contains spaces without quotes. | Check the directory and filename, create the destination directory if needed, and quote paths containing spaces. |
| The PDF is blank or missing page content | The requested URL may not have loaded as expected, or the page may depend on dynamic scripts. | Open the source URL in a browser, check the generated PDF, and investigate whether the page content is available to the renderer. |
| Content is clipped or breaks awkwardly | The paper size, orientation, or margins do not fit the page layout. | Try A4 or Letter, switch portrait or landscape, and adjust the documented margin options. |
| Headers or footers show literal placeholders or unexpected text | The option syntax or placeholder is not supported as entered. | Check the usage manual for the exact header/footer syntax and supported placeholders. |
| Conversion fails on user-provided HTML | Input may be malformed or unsafe to process. | Validate and sanitize user-provided HTML and JavaScript before conversion; never send untrusted input directly to the converter. |
6. Performance, reliability, and cost
This workflow runs a local command and writes a PDF to a path you choose. The research dossier provides no independent performance benchmarks, Windows compatibility study, or cost comparison, so conversion time and output quality should be assessed against your own page and environment. For repeated or automated conversions, check each output and consider the security implications of processing untrusted input.
The project identifies wkhtmltopdf as open-source software under LGPLv3. Installation assets and the listed stable series are on its downloads page; verify the current available Windows build there before adopting it.
Or skip the browser setup
If you need a hosted screenshot or PDF endpoint instead of installing a local renderer, ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-call API can return a PDF; this example requests one for a webpage:
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
See the ScreenshotNeo API documentation for authentication and PDF options. Cookie banners, popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
FAQ
Does wkhtmltopdf need a graphical desktop?
No. The project describes it as a headless command-line tool that does not require a display service.
Can I use the Windows 32-bit build?
The official downloads page lists both 32-bit and 64-bit Windows installer options. Check that the current download suits your system.
Where can I find all supported command-line options?
Use the project’s usage manual for the documented options and syntax.
Is the listed 0.12.6 release new?
The downloads page identifies 0.12.6 as the stable series and gives a release date of June 11, 2020. Check the official page for current release information.


