You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/TextRegion.md
+12-11
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
# Text Flow Regions #
2
+
_New in [:octicons-tag-24: 2.7.6](https://github.com/py-pdf/fpdf2/blob/master/CHANGELOG.md)_
2
3
3
4
**Notice:** As of fpdf2 release 2.7.6, this is an experimental feature. Both the API and the functionality may change before it is finalized, without prior notice.
4
5
5
-
Text regions are a hierarchy of classes that enable to flow text within a given outline. In the simplest case, it is just the running text column of a page. But it can also be a sequence of outlines, such as several parallel columns or the cells of a table. Other outlines may be combined by addition or subtraction to create more complex shapes.
6
+
Text regions are a hierarchy of classes that enable to flow text within a given outline. In the simplest case, it is just the running text column of a page. But it can also be a sequence of outlines, such as several parallel columns or the cells of a table. Other outlines may be combined by addition or subtraction to create more complex shapes.
6
7
7
8
There are two general categories of regions. One defines boundaries for running text that will just continue in the same manner one the next page. Those include columns and tables. The second category are distinct shapes. Examples would be a circle, a rectangle, a polygon of individual shape or even an image. They may be used individually, in combination, or to modify the outline of a multipage column. Shape regions will typically not cause a page break when they are full. In the future, a possibility to chain them may be implemented, so that a new shape will continue with the text that didn't fit into the previous one.
8
9
9
10
## General Operation ##
10
11
11
12
Using the different region types and combination always follows the same pattern. The main difference to the normal `FPDF.write()` method is that all added text will first be buffered, and you need to explicitly trigger its rendering on the page. This is necessary so that text can be aligned within the given boundaries even if its font, style, or size are arbitrarily varied along the way.
12
13
13
-
* Create the region instance
14
-
* If desired, add or subtract other shapes from it
15
-
* Use the `.write()` method to feed text into its buffer
16
-
* You can use the region instance as a context manager for filling, but you don't have to
17
-
* When used as a context manager, you can change all text styling parameters within that context, and they will be used by the added text, but won't leak to the surroundings
18
-
* For adding text with the already existing settings, just use the region instance as is.
14
+
* Create the region instance with an `FPDF` method.
15
+
* If desired, add or subtract other shapes from it (with geometric regions).
16
+
* Use the `.write()` method to feed text into its buffer.
17
+
* Best practise is to use the region instance as a context manager for filling.
18
+
* Text will be rendered automatically after closing the context.
19
+
* When used as a context manager, you can change all text styling parameters within that context, and they will be used by the added text, but won't leak to the surroundings
20
+
* For adding text with the already existing settings, just use the region instance as is. In that case, you'll have to explicitly use the `render()` method.
19
21
* Within a region, paragraphs can be inserted. The primary purpose of a paragraph is to apply a different horizontal alignment than the surrounding text.
20
-
* Once all the desired text is collected to fill a shape or a set of columns, you can call its `.render()` method to actually do so.
21
-
22
22
23
23
### Text Start Position ###
24
24
@@ -30,6 +30,7 @@ When rendering, the vertical start position of the text will be at the lowest on
30
30
Several region instances can exist at the same time. But only one of them can act as context manager at any given time. It is not currently possible to operate them recursively.
31
31
But it is possible to use them intermittingly. This will probably most often make sense between a columnar region and a table. You may have some running text ending at a given height, then insert a table with data, and finally continue the running text at the new height below the table within the existing column.
32
32
33
+
33
34
## Columns ##
34
35
35
36
The `FPDF.text_column() and ``FPDF.text_columns()` methods allow to create columnar layouts, with one or several columns respectively. Columns will always be of equal width.
@@ -64,8 +65,8 @@ Here we have a layout with three columns. Note that font type and text size can
64
65
65
66
#### Balanced Columns
66
67
67
-
Normally the columns will be filled left to right, and if the text ends before the page is full, the rightmost column will end up shorter than the others.
68
-
If you prefer that all columns on a page end on the same height, you can use the `balanced=True` argument. In that case a simple algorithm will be applied that attempts to approximately balance their bottoms.
68
+
Normally the columns will be filled left to right, and if the text ends before the page is full, the rightmost column will be shorter than the others.
69
+
If you prefer that all columns on a page end on the same height, you can use the `balance=True` argument. In that case a simple algorithm will be applied that attempts to approximately balance their bottoms.
69
70
70
71
```python
71
72
with pdf.text_columns(align="J", ncols=3, gutter=5, balanced=True) as cols:
0 commit comments