This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

wkhtmltopdf is a command line program that converts HTML to PDF using the WebKit rendering engine, as provided by Qt. Because it uses WebKit, you can use wkhtmltopdf to generate screenshots, or generate PDFs from Django or Rails or whatever, and the resulting PDFs will look awesome.

The typical install process includes downloading and compiling Qt, followed by downloading and installing wkhtmltopdf.

But you can’t really download and compile packages inside a Heroku dyno, so you need to vendor in any external binaries you might want to use (that aren’t Python packages that compile themselves). This package provides a simple way to include and use a wkhtmltopdf binary that has been compiled for the Heroku (Cedar stack) dyno environment.


Install it in the usual way:

pip install pywkher


One easy way of using wkhtmltopdf in your Python program is to use the included generate_pdf command. The generate_pdf command takes either a URL or an HTML document and returns a Python NamedTemporaryFile object referencing the generated PDF (which will be stored in the Heroku instance’s temporary directory).

Here’s an example of using the generate_pdf command to render a Django template as a PDF and return the resulting PDF as part of the HTTP response:

from os.path import basename
from wsgiref.util import FileWrapper

from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import get_template

from pywkher import generate_pdf

def return_a_pdf(request):
  template = get_template('my_awesome_template.html')
  html = template.render(RequestContext(request))
  pdf_file = generate_pdf(html=html)
  response = HttpResponse(FileWrapper(pdf_file), content_type='application/pdf')
  response['Content-Disposition'] = 'attachment;' % basename(
  response['Content-Length'] = pdf_file.tell()
  return response

Usage in Development

If you want to test your app locally, obviously the binary that’s compiled for Heroku isn’t going to work, unless your development or test environment closely mimics Heroku’s. However, the generate function will look for an environment variable named WKHTMLTOPDF_CMD and will only use the internally-bundled wkhtmltopdf binary if that environment variable is not set.

Therefore, if you’re on a Mac, do something like:

  • brew install wkhtmltopdf (Homebrew required for this)
  • export WKHTLMTOPDF_CMD=wkhtmltopdf
  • python (just an example)


Brad Phelan generated the binary that’s included here as part of his wkhtmltopdf-heroku gem. It’s thanks to his efforts that I didn’t have to go through the whole Heroku vulcan build process myself.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pywkher-new-params-1.0.4.tar.gz (10.9 MB) Copy SHA256 Checksum SHA256 Source Jun 18, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting