Layouts¶
-
class
pdfpug.layouts.
Grid
¶ A grid is a tabular structure that is divided vertically into
Row
and horizontally intoColumn
. This allows for creating complex layouts that would otherwise not be possible. The grid system is illustrated below for more clarity.The grid system supports a maximum horizontal size of 14 units. For instance, 2 columns of width 7 units can be placed in a single row. Or a single column of width 14 units. If the width of the columns in a row exceed 14 units, the extra columns will automatically flow to the next row.
>>> from pdfpug.layouts import Grid, Column >>> from pdfpug.modules import Paragraph, OrderedList >>> # Create left column and its contents >>> para = Paragraph('Python 3.x has several releases as listed,') >>> left_column = Column(width=5) >>> left_column.add_element(para) >>> # Create right column and its contents >>> releases = OrderedList(['3.0', '3.1', '3.2', '3.3', '3.4', '3.5', '3.6', '3.7']) >>> right_column = Column(width=5) >>> right_column.add_element(releases) >>> # Construct grid >>> grid = Grid() >>> grid.add_layout(left_column) >>> grid.add_layout(right_column)
-
class
pdfpug.layouts.
Column
(**kwargs)¶ The grid system divides horizontal space into indivisible units called Columns. The
Column
layout is the one that contain the actual content likeParagraph
etc. Think of it as a container that holds content in a vertical layout.Parameters: width (int) – Width of the column (should be in the range of 1-14) -
add_element
(element)¶ Add element to the column
Parameters: element (BasePugElement) – Element to be added to the column Return type: None
-
-
class
pdfpug.layouts.
Row
(**kwargs)¶ Rows are groups of columns which are aligned horizontally. When a group of columns exceed the grid width (14 units), the content automatically flows to the next row which is to say that rows are created automatically as required.
However, if explicit control is required for achieving a particular layout it can be declared with columns added to it. For instance, in the illustration below, the first row has 2 columns A, B which occupy a total of 10 units. If the row was not explicitly declared, then column C would be placed in the first row due to available space.