File: CombineWithLivereload.md

package info (click to toggle)
fpdf2 2.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,860 kB
  • sloc: python: 39,487; sh: 133; makefile: 12
file content (23 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Combine with livereload

A nice feature of PDF readers is when they detect changes to the `.pdf` files open
and automatically reload them in the viewer.
Adobe Acrobat Reader **does not** provide this feature but other viewers offer it,
like the free & open source [Sumatra PDF Reader](https://www.sumatrapdfreader.org) under Windows.

When using such PDF reader, it can be very useful to use a "watch" mode,
so that every change to the Python code will trigger the regeneration of the PDF file.

The following script is an example of using [`livereload`](https://pypi.org/project/livereload/) with `fpdf2` to do that.
Launched without parameters, this script only generates a PDF document.
But when launched with `--watch` as argument,
it will detect changes to the Python script itself,
and then reload itself with [`xreload`](https://pypi.org/project/xreload/),
and finally regenerate the PDF document.

```python
{% include "../tutorial/watch_with_livereload.py" %}
```

Note that the module reloading mechanism provided by `xreload`
has several limitations, _cf._ [`xreload.py`](https://github.com/Lucas-C/xreload/blob/master/src/xreload.py#L8).