wkhtmltopdf
raw JSON → 0.2 verified Fri May 01 auth: no python maintenance
Simple Python wrapper for wkhtmltopdf that converts HTML to PDF using the wkhtmltopdf command-line tool. Version 0.2 is the latest release. The library has been in maintenance mode and is no longer actively developed.
pip install wkhtmltopdf Common errors
error wkhtmltopdf.utils.WkHtmlToPdfError: 'wkhtmltopdf' not found in PATH ↓
cause The wkhtmltopdf binary is not installed or not in your system's PATH.
fix
Install wkhtmltopdf from the official website and add it to PATH. Verify with 'which wkhtmltopdf' on Linux/Mac or 'where wkhtmltopdf' on Windows.
error AttributeError: module 'wkhtmltopdf' has no attribute 'convert' ↓
cause Incorrect import or usage. The module provides a direct function convert, but it's possible the user imported a different module with the same name.
fix
Use 'import wkhtmltopdf' and call 'wkhtmltopdf.convert()'. Ensure no other wkhtmltopdf.py file shadows the library.
error FileNotFoundError: [Errno 2] No such file or directory: 'wkhtmltopdf' ↓
cause The wkhtmltopdf binary is not installed or not in PATH.
fix
Same as above: install wkhtmltopdf and add to PATH.
Warnings
deprecated wkhtmltopdf is no longer actively maintained. Consider using alternatives like pdfkit, weasyprint, or selenium. ↓
fix Switch to a maintained library such as pdfkit (pip install pdfkit) or weasyprint.
gotcha The library requires the wkhtmltopdf binary to be installed on your system and accessible in PATH. pip install does not install the binary. ↓
fix Install wkhtmltopdf from https://wkhtmltopdf.org/downloads.html and ensure it is in your PATH.
Imports
- wkhtmltopdf
import wkhtmltopdf
Quickstart
import wkhtmltopdf
# Convert HTML to PDF
with open('input.html', 'w') as f:
f.write('<h1>Hello World</h1>')
pdf = wkhtmltopdf.convert('input.html')
with open('output.pdf', 'wb') as f:
f.write(pdf)