@@ -10,7 +10,7 @@ PDF generation in python using
1010Wkhtmltopdf binaries are precompiled and included in the package making
1111pydf easier to use, in particular this means pydf works on heroku.
1212
13- Currently using **wkhtmltopdf 0.12.4 (with patched qt) **.
13+ Currently using **wkhtmltopdf 0.12.4 (with patched qt) **, requires ** Python 3.6+ ** .
1414
1515Install
1616-------
@@ -19,7 +19,7 @@ Install
1919
2020 pip install python-pdf
2121
22- (pydf was taken, but I guess python-pdf is a clearer name anyway.)
22+ For python 2 use `` pip install python-pdf==0.30.0 ``.
2323
2424Basic Usage
2525-----------
@@ -28,11 +28,7 @@ Basic Usage
2828
2929 import pydf
3030 pdf = pydf.generate_pdf(' <h1>this is html</h1>' )
31- with open (' test_doc.pdf' , ' w' ) as f:
32- f.write(pdf)
33-
34- pdf = pydf.generate_pdf(' www.google.com' )
35- with open (' google.pdf' , ' w' ) as f:
31+ with open (' test_doc.pdf' , ' wb' ) as f:
3632 f.write(pdf)
3733
3834 Async Usage
@@ -44,38 +40,28 @@ at the same time. Thus the time taken to spin up processes doesn't slow you down
4440
4541.. code :: python
4642
47- async def go_async ():
48- count = 20
49- apydf = AsyncPydf(max_processes = 20 )
50-
51- async def gen (i_ ):
52- pdf = await apydf.generate_pdf(
53- html,
54- title = ' Benchmark' ,
55- author = ' Samuel Colvin' ,
56- subject = ' Mock Invoice' ,
57- page_size = ' A4' ,
58- zoom = ' 1.25' ,
59- margin_left = ' 8mm' ,
60- margin_right = ' 8mm' ,
61- )
62- print (f ' { i_:03 } : { len (pdf)} ' )
63- file = OUT_DIR / f ' output_ { i_:03 } .pdf '
64- file .write_bytes(pdf)
65-
66- coros = []
67- for i in range (count):
68- coros.append(gen(i))
69- await asyncio.gather(* coros)
70- return count
71-
72- loop = asyncio.get_event_loop()
73- loop.run_until_complete(go_async())
43+ from pathlib import Path
44+ from pydf import AsyncPydf
45+
46+ async def generate_async ():
47+ apydf = AsyncPydf()
48+
49+ async def gen (i ):
50+ pdf_content = await apydf.generate_pdf(' <h1>this is html</h1>' )
51+ Path(f ' output_ { i:03 } .pdf ' ).write_bytes(pdf_content)
52+
53+ coros = [gen(i) for i in range (50 )]
54+ await asyncio.gather(* coros)
55+
56+ loop = asyncio.get_event_loop()
57+ loop.run_until_complete(generate_async())
7458
7559
7660 See `benchmarks/run.py <https://github.com/tutorcruncher/pydf/blob/master/benchmark/run.py >`__
7761for a full example.
7862
63+ Locally generating an entire invoice goes from 0.372s/pdf to 0.035s/pdf with the async model.
64+
7965API
8066---
8167
@@ -90,8 +76,7 @@ For details on extra arguments see the output of get\_help() and
9076get\_ extended\_ help()
9177
9278All arguments whether specified or caught with extra\_ kwargs are
93- converted to command line args with
94- ``'--' + original_name.replace('_', '-') ``.
79+ converted to command line args with ``'--' + original_name.replace('_', '-') ``.
9580
9681Arguments which are True are passed with no value eg. just --quiet,
9782False and None arguments are missed, everything else is passed with
0 commit comments