django-wkhtmltopdf is a Django library that allows you to render HTML templates to PDF documents using the external `wkhtmltopdf` utility. It provides class-based views and utility functions for PDF generation within Django projects. The current version is 3.4.0, and it maintains a steady release cadence with a focus on stability and compatibility with newer Django versions.
pip install django-wkhtmltopdfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a PDF view using `PDFTemplateView`. Ensure the `wkhtmltopdf` binary is installed on your system and its path is set in `WKHTMLTOPDF_CMD` in your Django settings. It renders `hello_pdf.html` into a downloadable PDF.
Manually install the `wkhtmltopdf` executable for your operating system (e.g., via apt, brew, or direct download). Ensure it's in your system's PATH or configure its full path in `settings.WKHTMLTOPDF_CMD`.
Verify the absolute path to your `wkhtmltopdf` binary (e.g., `/usr/local/bin/wkhtmltopdf` on Linux/macOS, `C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe` on Windows) and set `WKHTMLTOPDF_CMD = '/path/to/wkhtmltopdf'` in your `settings.py`.
Use absolute URLs for static files (e.g., `{{ request.build_absolute_uri(STATIC_URL) }}path/to/my.css`). For local files, you might need to use `file://` paths directly in your template or pass `cmd_options={'enable-local-file-access': True}` to your view or utility function.If experiencing rendering issues, try installing `wkhtmltopdf` version 0.12.6. You may also need to experiment with specific `cmd_options` for `wkhtmltopdf` such as `--enable-javascript`, `--no-stop-slow-scripts`, or `--print-media-type`.
No dependency data recorded yet.