Skip to main content

Convert JavaScript dependent Flask templates into PDFs with wkhtmltopdf.

Project description

Flask-WkHTMLtoPDF

build status doc status

Flask-WkHTMLtoPDF allows you to easily convert JavaScript dependent Flask templates into PDFs with wkhtmltopdf. For complete documentation, please visit http://flask-wkhtmltopdf.readthedocs.org/en/latest/?badge=latest.

Installation

Install the extension with one of the following commands:

$ easy_install flask-wkhtmltopdf

or alternatively if you have pip installed:

$ pip install flask-wkhtmltopdf

You will also need to install the WkHTMLtoPDF command line library from http://wkhtmltopdf.org/downloads.html. Alternatively, you can install from the command line for unix based machines by finding the appropriate distrubution on http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/. For instance, for linux:

$ wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-precise-amd64.deb
$ sudo dpkg -i wkhtmltox-0.12.2.1_linux-precise-amd64.deb

Usage

First setup in your main Flask file.

from flask_wkhtmltopdf import Wkhtmltopdf

        app = Flask(__name__)
        wkhtmltopdf = Wkhtmltopdf(app)

Then add these to your app's config

WKHTMLTOPDF_BIN_PATH = r'C:\Program Files\wkhtmltopdf\bin' #path to your wkhtmltopdf installation.
PDF_DIR_PATH =  os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static', 'pdf')

To convert a flask template into a PDF, simply use the render_template_to_pdf() function.

render_template_to_pdf('test.html', download=True, save=False, param='hello')

Contributing

Contributions are more than welcomed. Please follow these steps:

  1. Fork this repository
  2. Make your changes
  3. Test your changes locally:
$ python setup.py test
  1. Submit a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-WkHTMLtoPDF-tmsl-0.1.2.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

Flask_WkHTMLtoPDF_tmsl-0.1.2-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page