Skip to content

Commit

Permalink
Docs on using fpdf2 with gunicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Sep 4, 2024
1 parent 33eb7ed commit 4ccc4f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
* [`Templates`](https://py-pdf.github.io/fpdf2/fpdf/Templates.html) can now be also defined in JSON files.
* support to optionally set `wrapmode` in templates (default `"WORD"` can optionally be set to `"CHAR"` to support wrapping on characters for scripts like Chinese or Japanese) - _cf._ [#1159](https://github.com/py-pdf/fpdf2/issues/1159) - thanks to @carlhiggs
* support for quadratic and cubic Bézier curves with [`FPDF.bezier()`](https://py-pdf.github.io/fpdf2/fpdf/Shapes.html#fpdf.fpdf.FPDF.bezier) - thanks to @awmc000
- documentation on how to use `fpdf2` with [gunicorn](https://gunicorn.org/): [link to docs](https://py-pdf.github.io/fpdf2/UsageInWebAPI.html#gunicorn)
* feature to identify the Unicode script of the input text and break it into fragments when different scripts are used, improving [text shaping](https://py-pdf.github.io/fpdf2/TextShaping.html) results
* [`FPDF.image()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.image): now handles `keep_aspect_ratio` in combination with an enum value provided to `x`
* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): now supports CSS page breaks properties : [documentation](https://py-pdf.github.io/fpdf2/HTML.html#page-breaks)
Expand Down
22 changes: 22 additions & 0 deletions docs/UsageInWebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def hello_world():
```


## gunicorn ##
[Gunicorn 'Green Unicorn'](https://gunicorn.org/) is a Python WSGI HTTP Server for UNIX.

The following code can be placed in a `gunicorn_fpdf2.py` file and launched using `gunicorn -w 4 gunicorn_fpdf2:app`:

```python
from fpdf import FPDF

def app(environ, start_response):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=12)
pdf.cell(text="Hello world!")
data = bytes(pdf.output())
start_response("200 OK", [
("Content-Type", "application/pdf"),
("Content-Length", str(len(data)))
])
return iter([data])
```


## AWS lambda ##
The following code demonstrates some minimal [AWS lambda handler function](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html)
that returns a PDF file as binary output:
Expand Down

0 comments on commit 4ccc4f3

Please sign in to comment.