|
| 1 | +pydf |
| 2 | +==== |
| 3 | + |
| 4 | + |
| 5 | +|Build Status| |codecov.io| |PyPI Status| |license| |
| 6 | + |
| 7 | +PDF generation in python using |
| 8 | +`wkhtmltopdf <http://wkhtmltopdf.org/>`__. |
| 9 | + |
| 10 | +Wkhtmltopdf binaries are precompiled and included in the package making |
| 11 | +pydf easier to use, in particular this means pydf works on heroku. |
| 12 | + |
| 13 | +Currently using **wkhtmltopdf 0.12.4 (with patched qt)**. |
| 14 | + |
| 15 | +Install |
| 16 | +------- |
| 17 | + |
| 18 | +:: |
| 19 | + |
| 20 | + pip install python-pdf |
| 21 | + |
| 22 | +(pydf was taken, but I guess python-pdf is a clearer name anyway.) |
| 23 | + |
| 24 | +Changelog |
| 25 | +--------- |
| 26 | + |
| 27 | +0.3 |
| 28 | +~~~ |
| 29 | + |
| 30 | +- uprev wkhtmltopdf from **0.12.2 (beta)** to **0.12.4**. |
| 31 | +- code cleanup |
| 32 | + |
| 33 | +Basic Usage |
| 34 | +----------- |
| 35 | + |
| 36 | +.. code:: python |
| 37 | +
|
| 38 | + import pydf |
| 39 | + pdf = pydf.generate_pdf('<h1>this is html</h1>') |
| 40 | + with open('test_doc.pdf', 'w') as f: |
| 41 | + f.write(pdf) |
| 42 | +
|
| 43 | + pdf = pydf.generate_pdf('www.google.com') |
| 44 | + with open('google.pdf', 'w') as f: |
| 45 | + f.write(pdf) |
| 46 | +
|
| 47 | +API |
| 48 | +--- |
| 49 | + |
| 50 | +**generate\_pdf(source, [\*\*kwargs])** |
| 51 | + |
| 52 | +Generate a pdf from either a url or a html string. |
| 53 | + |
| 54 | +After the html and url arguments all other arguments are passed straight |
| 55 | +to wkhtmltopdf |
| 56 | + |
| 57 | +For details on extra arguments see the output of get\_help() and |
| 58 | +get\_extended\_help() |
| 59 | + |
| 60 | +All arguments whether specified or caught with extra\_kwargs are |
| 61 | +converted to command line args with |
| 62 | +``'--' + original_name.replace('_', '-')``. |
| 63 | + |
| 64 | +Arguments which are True are passed with no value eg. just --quiet, |
| 65 | +False and None arguments are missed, everything else is passed with |
| 66 | +str(value). |
| 67 | + |
| 68 | +**Arguments:** |
| 69 | + |
| 70 | +- ``source``: html string to generate pdf from or url to get |
| 71 | +- ``quiet``: bool |
| 72 | +- ``grayscale``: bool |
| 73 | +- ``lowquality``: bool |
| 74 | +- ``margin_bottom``: string eg. 10mm |
| 75 | +- ``margin_left``: string eg. 10mm |
| 76 | +- ``margin_right``: string eg. 10mm |
| 77 | +- ``margin_top``: string eg. 10mm |
| 78 | +- ``orientation``: Portrait or Landscape |
| 79 | +- ``page_height``: string eg. 10mm |
| 80 | +- ``page_width``: string eg. 10mm |
| 81 | +- ``page_size``: string: A4, Letter, etc. |
| 82 | +- ``image_dpi``: int default 600 |
| 83 | +- ``image_quality``: int default 94 |
| 84 | +- ``extra_kwargs``: any exotic extra options for wkhtmltopdf |
| 85 | + |
| 86 | +Returns string representing pdf |
| 87 | + |
| 88 | +**get\_version()** |
| 89 | + |
| 90 | +Get version of pydf and wkhtmltopdf binary |
| 91 | + |
| 92 | +**get\_help()** |
| 93 | + |
| 94 | +get help string from wkhtmltopdf binary uses -h command line option |
| 95 | + |
| 96 | +**get\_extended\_help()** |
| 97 | + |
| 98 | +get extended help string from wkhtmltopdf binary uses -H command line |
| 99 | +option |
| 100 | + |
| 101 | +**execute\_wk(\*args)** |
| 102 | + |
| 103 | +Low level function to call wkhtmltopdf, arguments are added to |
| 104 | +wkhtmltopdf binary and passed to subprocess with not processing. |
| 105 | + |
| 106 | +.. |Build Status| image:: https://travis-ci.org/samuelcolvin/pydf.svg?branch=master |
| 107 | + :target: https://travis-ci.org/samuelcolvin/pydf |
| 108 | +.. |codecov.io| image:: http://codecov.io/github/samuelcolvin/pydf/coverage.svg?branch=master |
| 109 | + :target: http://codecov.io/github/samuelcolvin/pydf?branch=master |
| 110 | +.. |PyPI Status| image:: https://img.shields.io/pypi/v/pydf.svg?style=flat |
| 111 | + :target: https://pypi.python.org/pypi/pydf |
| 112 | +.. |license| image:: https://img.shields.io/pypi/l/pydf.svg |
| 113 | + :target: https://github.com/samuelcolvin/pydf |
0 commit comments