Skip to content

aguegu/wkhtmltopdf-wrapper

 
 

Repository files navigation

wkhtmltopdf-wrapper

A simple and direct python wrapper for the wkhtmltopdf lib inspired by inspired by Qoda's python-wkhtmltopdf

Requirements

System:

  • Linux 32/64 or OSX only (Windows is not supported at this stage)
  • wkhtmltopdf
  • python 2.5+ / python3

Installation

wkhtmltopdf (Linux)

  1. Install Fonts:
$ sudo apt-get install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
  1. Install wkhtmltopdf

goto http://wkhtmltopdf.org/downloads.html for the latest release (Recommended)

wkhtmltopdf (OSX)

or goto http://wkhtmltopdf.org/downloads.html for the latest release (Recommended)

wkhtmltopdf-wrapper (Any Platform)

  1. PIP:
$ pip install wkhtmltopdf-wrapper

or

$ pip install git+https://github.com/aguegu/wkhtmltopdf-wrapper.git
  1. Development:
$ git clone https://github.com/aguegu/wkhtmltopdf-wrapper.git
$ cd wkhtmltopdf-wrapper
$ virtualenv .
$ pip install -r requirements.pip

Usage

the option_string would be sent to the wkhtmltopdf command line in exactly the same shape. so the options can be anything as long as the wkhtmltopdf supports. check its usage. This lib is just as simple as that. If anything goes wrong, just check the doc. If the command execute ok with wkhtmltopdf dircetly, this wrapper should work too.

As I check qoda/python-wkhtmltopdf, where this repo forked from, it tried to prase args. But it only include a small set of the arguments the command supports. Furthermore, it set default values to this set of arguments and pass them all to the command. For me, it is totally unnecessary and even mistakeful. There is default setting setup and doc in the command. Some arugments may not even work together, as --page-size and --page-height, --page-width. So my solution is just pass the option in as a string, Lazy, flexible and effective.

from class:

  from wkhtmltopdfwrapper import WKHtmlToPdf
  
  wkhtmltopdf = WKHtmlToPdf('-T 20 -B 20 -g --zoom 1.5')
  # option_string
  
  wkhtmltopdf.render('http://www.example.com', '~/example.pdf')
  # source url, output file path

from method:

  from wkhtmltopdfwrapper import wkhtmltopdf
  wkhtmltopdf('example.com', '~/example.pdf', '-T 20 -B 20 -g --zoom 1.5')

from commandline (installed):

  $ python -m wkhtmltopdfwrapper.__init__ example.com ~/example.pdf -T 20 -B 20 -g --zoom 1.5

About

A simple and direct python wrapper for the wkhtmltopdf exec.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%